Php $ _ POST tutorial on getting html form data. The $ _ POST variable is used to collect values from the methodpost form. The information sent from a form with the POST method is invisible to anyone (the $ _ POST variable is not displayed in the browser's address bar to collect values from the form with method = "post. The information sent from a form with the POST method is invisible to anyone (not displayed in the address bar of the browser) and there is no limit on the amount of information sent.
Let's take a look at the simplest example.
If I enter Hello,
The post. php file code is as follows:
| The code is as follows: |
|
|
You are . |
The output result is
You are Hello
How can I obtain the image single-choice button for post? the example is as follows:
Radiopost. php file
In this way, if you select one, all the values will be exported, and the checkbox will be different. you can pay attention to this.
Checkboxpost. php file
| The code is as follows: |
|
|
Print_r ($ _ POST ['ABCDE']); |
The output is an array.
Note:
Variables sent through http post are not displayed in the URL.
The variable has no length limit.
$ _ POST and php: // input can get the value. $ HTTP_RAW_POST_DATA is empty.
$ _ POST organizes submitted data in an associated array and performs encoding, such as urldecode or even encoding conversion.
Php: // input: raw POST data that has not been processed can be obtained by reading files from the input stream.
Php: // input allows reading original POST data. Compared with $ HTTP_RAW_POST_DATA, it puts less pressure on the memory and does not require any special php. ini settings. Php: // input cannot be used for enctype = "multipart/form-data ".
Here we will expand the post simulation method.
| The code is as follows: |
|
|
<? PHP
$ Flag = 0;
// Data to be post
$ Argv = array (
'Var1' => 'ABC ',
'Var2' => '');
// Construct the string to post
Foreach ($ argv as $ key => $ value ){
If ($ flag! = 0 ){
$ Params. = "&";
$ Flag = 1;
}
$ Params. = $ key. "="; $ params. = urlencode ($ value );
$ Flag = 1;
}
$ Length = strlen ($ params );
// Create a socket connection
$ Fp = fsockopen ("127.0.0.1", 80, $ errno, $ errstr, 10) or exit ($ errstr. "--->". $ errno );
// Construct the post request header
$ Header = "POST/mobile/try. php HTTP/1.1 ";
$ Header. = "Host: 127.0.0.1 ";
$ Header. = "Referer:/mobile/sendpost. php ";
$ Header. = "Content-Type: application/x-www-form-urlencoded ";
$ Header. = "Content-Length:". $ length ."";
$ Header. = "Connection: Close ";
// Add the post string
$ Header. = $ params ."";
// Send post data
Fputs ($ fp, $ header );
$ Inheader = 1;
While (! Feof ($ fp )){
$ Line = fgets ($ fp, 1024); // only the returned data on the page is displayed when the request packet header is removed.
If ($ inheader & ($ line = "n" | $ line = "")){
$ Inheader = 0;
}
If ($ inheader = 0 ){
Echo $ line;
}
}
Fclose ($ fp );
?> |
The values variable is used to collect the values in the form from method = "post. The information sent from a form with the POST method is invisible to anyone (not displayed in the browser's address bar...