The Little Guy Posted October 30, 2009 Share Posted October 30, 2009 I am using sockets to create a php web server, I would like to know how does a web browser send POST data to a web server from a form? I thought that I could look in the request, and find the post data, but it wasn't in there. Here is what was in there: POST /postdata.php HTTP/1.1 Host: localhost:3333 Connection: keep-alive User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.27 Safari/532.0 Referer: http://localhost:3333/postdata.php Content-Length: 36 Cache-Control: max-age=0 Origin: http://localhost:3333 Content-Type: application/x-www-form-urlencoded Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 the form field's name was: "name" and the value I entered was: "ryan" I then press submit, and I don't know where I would find how it was sent... So if anyone has any info how to get post data, please let me know! Link to comment https://forums.phpfreaks.com/topic/179563-solved-reading-post-data-from-browser/ Share on other sites More sharing options...
mpharo Posted October 30, 2009 Share Posted October 30, 2009 I am not sure if this was what you were looking for but... Post data is stored in an array called $_POST... You can do something like this... <?php foreach($_POST as $key=>$val) { echo "Key: $key Value: $val<br>"; } ?> This will output each post element. You can specify single post elements by a typicall array echo...ie... <?php echo $_POST['fieldname']; ?> Link to comment https://forums.phpfreaks.com/topic/179563-solved-reading-post-data-from-browser/#findComment-947513 Share on other sites More sharing options...
The Little Guy Posted October 30, 2009 Author Share Posted October 30, 2009 No, That isn't what I was looking for my project runs from a terminal/command line, there is no post data there. Link to comment https://forums.phpfreaks.com/topic/179563-solved-reading-post-data-from-browser/#findComment-947525 Share on other sites More sharing options...
mpharo Posted October 30, 2009 Share Posted October 30, 2009 You will need to use stdin variables instead of post, it will not work correctly unless you use stdin... Link to comment https://forums.phpfreaks.com/topic/179563-solved-reading-post-data-from-browser/#findComment-947550 Share on other sites More sharing options...
The Little Guy Posted October 30, 2009 Author Share Posted October 30, 2009 could you give an example of what you mean? Link to comment https://forums.phpfreaks.com/topic/179563-solved-reading-post-data-from-browser/#findComment-947556 Share on other sites More sharing options...
The Little Guy Posted October 30, 2009 Author Share Posted October 30, 2009 I have realized that this is sent in 2 parts, The header, then the post data... it would looks something like this: POST /postdata.php HTTP/1.1 Host: localhost:3333 Connection: keep-alive User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.27 Safari/532.0 Referer: http://localhost:3333/postdata.php Content-Length: 36 Cache-Control: max-age=0 Origin: http://localhost:3333 Content-Type: application/x-www-form-urlencoded Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 name=ryan note the extra line at the end compared to my first post... Link to comment https://forums.phpfreaks.com/topic/179563-solved-reading-post-data-from-browser/#findComment-947558 Share on other sites More sharing options...
The Little Guy Posted October 30, 2009 Author Share Posted October 30, 2009 And that leads me to say I figured out my problem! I needed to add an extra socket_recv in my code Link to comment https://forums.phpfreaks.com/topic/179563-solved-reading-post-data-from-browser/#findComment-947564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.