Hi all, Im trying to create an test environment where a php page can complete a XML document and then proceed to post said xml document to a remote server. Its based on a telephone database currently stored on a local mysql server. The user clicks the telephone number and this is then inserted into the XML document completing the document. This is then posted to a remote server. Ive written the PHP so that when the user clicks from the displayed page, it loads a link to: http://localhost/xml_post.php?tel=0123456789 but how do I get the xml_post to insert the string into the pre-written xml and then post it to the server? the xml is small and basic: <?xml version='1.0' encoding='UTF-8' ?> <username>test</username> <password>123</password> <tel_number>INSERTED STRING</tel_number> Basically it goes: HTML link-> PHP -> XML -> database any help would be appericiated thank you! Mathew
Hi, This is quite simple really. You need to use curl. (an example) So this is how I would do it. 1. create an xml file with code like this. <?php $file = 'directory/file.xml'; $fh = fopen($file,'w+'); fwrite($fh,'<?xml version='1.0' encoding='UTF-8' ?> <username>test</username> <password>123</password> <tel_number>'.$_GET['tel'].'</tel_number>'); fclose($fh); ?> PHP: 2. Submit the file <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, array('xmlfile'=>"@$file")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL,'http://yourremotewebsite.com/page.php'); curl_exec($ch); curl_close($ch); ?> PHP: 3. delete the file again <?php unlink($file); ?> PHP: (All of the code would be in the same file. None of it is tested or deemed to be secure. Improvements have to be made) Hope this helps.
No problem. If you have any more problems simply post the code you are using, the problem you encounter and I am sure me or someone else will be able to help you out.
If you all like this then feel free to add to my reputation. (star button on the very left under each post)
lol, forgive me im presently struggling with how to install curl onto windows XP WAMPServer 2.0 - but thats by the by. The code you have written, im assuming they are all not individual files? more snipits of code that I can put into existing web pages? apart from the code that creates the XML file (your top snipit) so its still a case of: HTML Page > user clicks link and it creates a url of : post_xml.php?tel=0123456789 this is then put into post_xml.php and the tel number populates the variable 'tel' then using 2nd snipit of code (still inside post_xml.php) the document can then be posted to the server? is that right or am I getting the method wrong? thanks Mathew
Yes all the snippets go on the same page and you can add more code as you want. Correct Also correct. Sorry no idea how to or even if wampp would support curl