Jump to content

[SOLVED] Reading POST Data From Browser


The Little Guy

Recommended Posts

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

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'];

?>

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.