Hodo Posted June 13, 2007 Share Posted June 13, 2007 Probably not the correct words in the subject but I'll try to explain. I have software in c++ that sends data to a php file on my website. I have all the connections in place since it echoes back an ok to my code. Problem is the data portion is not being read by the php. I dont know how to reference it. this is what I send: data ="Hello World"; len = strlen(data); POST /mydir/getmessage.php HTTP/1.1\n Host: www.mysite.com:80\n User-Agent: MyAgent/1.0 \n Accept: */*\n Content-Length: len \n Content-Type: application/x-www-form-urlencoded; charset=UTF-8\n\n" data; php file on the server <?php printf("RETURN: OK %s",$Data); ?> This sends back OK but not an echo of the data. Should be OK Hello World. Can someone explain how to read the data file being sent? I would like to add a few things like name,password,etc to the data I send but not sure how to index or split it out on the php side. Quote Link to comment Share on other sites More sharing options...
trq Posted June 13, 2007 Share Posted June 13, 2007 <?php if (isset($_POST['data'])) { printf("RETURN: OK %s",$_POST['data']); } ?> Quote Link to comment Share on other sites More sharing options...
rab Posted June 13, 2007 Share Posted June 13, 2007 Don't forget that your using POST, you'll need to urlencode your content. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted June 13, 2007 Share Posted June 13, 2007 if i were you, i'd use the c++ application to store the data in a valid XML document and use an xml parser on the php side. Quote Link to comment Share on other sites More sharing options...
Hodo Posted June 13, 2007 Author Share Posted June 13, 2007 @thorpe the data is urlencoded before I send it your example returns OK as well probably because it's not parsed at the php level. Here is the received data no return HTTP/1.1 200 OK no return Date: Wed, 13 Jun 2007 18:22:24 GMT no return Server: Apache no return Transfer-Encoding: chunked no return Content-Type: text/html no return no return 47 no return no return no return <HTML> no return <HEAD> no return </HEAD> no return <BODY> OK <<<<<<<<<<<<<<<<<<<<<< THIS IS WHAT IS PERTENIENT no return </BODY> no return </HTML> What I need to confirm is that the data I sent is actually received. How does php parse the input. Say I sent a data like data = "Megaman+foofoo9"; there are 2 words in the data so in php $name = firstword; $pass = secondword; I should be able to print, or echo these values to prove they got parsed. @boo_lolly This data has to be sent to a webstie and parsed there for insertion into a database or checks against a database. thanks for the reply... Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted June 13, 2007 Share Posted June 13, 2007 again, it can be done in php using a valid XML document. i'm not sure what your point was. please explain. Quote Link to comment Share on other sites More sharing options...
Hodo Posted June 13, 2007 Author Share Posted June 13, 2007 @boo_lolly I have a program running on my computer at the house. when it executes a function in that c++ code calls my website and is supposed to deposit information If the xml of which you speak is on the website, how does it get launched only when my program runs? If the xml is local to my machine then again it will have to contact my website on its own and send the standard html string which causes the same problem. What do you propose? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted June 14, 2007 Share Posted June 14, 2007 the XML is not on your website. the XML document is created dynamically everytime the C++ application runs. the data that the C++ application creates will be stored in an XML document. then you can send the XML document to the website. if you google XML and read a little about it, you'll soon find that it is one of, if not, the most efficient way of transfering data from one medium to another. it doesn't matter where it starts or ends. plus, it's a really good thing to know XML. it's the future. questions: what does the C++ app do exactly? what kind of data does it generate? what is it for? Quote Link to comment Share on other sites More sharing options...
Hodo Posted June 14, 2007 Author Share Posted June 14, 2007 So now I have a xml formatted by c++ then I have to somehow send it to my website dynamicly. No prob, now I have to tell my php to act on it, parse the data then store the info in the database. sounds like alot of extra work to do that as opposed to sending the data in a simple post since Im inside the winsock already and the post method has provisions to send the data in a single call the way im doing it now. Data sent is an ip address and a name. 2 pieces of info should be trivial in php but dont know how to parse the input message to get the 2 bits of data. thanks for reply Quote Link to comment Share on other sites More sharing options...
trq Posted June 14, 2007 Share Posted June 14, 2007 sounds like alot of extra work to do that as opposed to sending the data in a simple post I agree. Lets first see exactly what was posted to the php script. What does.... <?php print_r($_POST); ?> output? Quote Link to comment Share on other sites More sharing options...
Hodo Posted June 14, 2007 Author Share Posted June 14, 2007 ah I smell some magic! no return <HTML> no return <HEAD> no return </HEAD> no return <BODY> no return Array no return ( no return [data] => HYPERKAT <<<<< THIS IS THE DATA I SENT! no return ) no return no return </BODY> no return </HTML> no return no return no return 0 Sorry for being such a noob on this, now to extract it as a single var and put it in the file Thanks for reply! Quote Link to comment Share on other sites More sharing options...
trq Posted June 14, 2007 Share Posted June 14, 2007 What exactly is producing this output? no return <HTML> no return <HEAD> no return </HEAD> no return <BODY> no return Array no return ( no return [data] => HYPERKAT <<<<< THIS IS THE DATA I SENT! no return ) no return no return </BODY> no return </HTML> no return no return no return 0 Can we see the output of... <?php print_r($_POST); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.