PHP Explaining transmitting POST Data to the Server
When you POST da开发者_开发知识库ta to the server in PHP, does it get transmitted through the headers? How does POSTing work?
This is an example http POST:
POST /login.php HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0
Content-Length: 27
Content-Type: application/x-www-form-urlencoded
userid=joe&password=guessme
As you see, it's not transmitted through the headers, it's the actual content of the POST.
When you post the data is sent in the body of the request.
You should install firebug, and post a form. Look at the net tab to see what is sent.
IN HTTP, a request consists of twp parts, the header and the body. These are seperateed by two newline characters. When you POST somthing, you are sending data in the body part of the request, after the headers. Usually, when POSTing a web form, it is sending the form data in the data section of the request, formatted like a URL query string. Example: foo=bar&baz=bat
Great article Better article explaining POST/GET
POST
includes name/value pairs in the body of the request, while GET
does so in the query string.
The way that PHP does this is to store all the "posted" values into an associative array called $_POST
.
$quantity = $_POST['quantity'];
$item = $_POST['item'];
Also you can view the Request methods section of the Hype Transfer Protocol on Wiki, it has the definitions and information on all of the different methods.
精彩评论