Let's take a look at the simplest example.
| The code is as follows |
Copy Code |
<form action = "post.php" method = "POST" > Name: <input type= "text" name= "username"/> <input type = "Submit" value= "OK"/> </form> |
If I input hello,
The post.php file code is as follows
| The code is as follows |
Copy Code |
You are <?php echo $_post["username"]?>. |
The output result is
You are Hello
So how does post get like a radio button, the example below
| The code is as follows |
Copy Code |
<form action = "radiopost.php" method = "POST" > <input type= "Radio" name= "ABCDE" value = "Apple" >apple</input><br/> <input type= "Radio" name= "ABCDE" value = "Orange" >orange</input><br/> <input type= "Radio" name= "ABCDE" value = "Mango" >mango</input><br/> <input type= "Submit" value= "OK" > </form> |
radiopost.php file
| The code is as follows |
Copy Code |
<?php echo $_post["ABCDE"]?> |
So you choose that and you lose the value of that, for the checkbox will be different, this you can pay attention to
| The code is as follows |
Copy Code |
<form action = "checkboxpost.php" method = "POST" > <input type= "checkbox" Name= "abcde[]" value = "Apple" >apple</input><br/> <input type= "checkbox" Name= "abcde[]" value = "Orange" >orange</input><br/> <input type= "checkbox" Name= "abcde[]" value = "Mango" >mango</input><br/> <input type= "Submit" value= "OK" > </form> |
checkboxpost.php file
| The code is as follows |
Copy Code |
Print_r ($_post[' ABCDE ')); |
The output is in the form of arrays.
Note:
Variables sent over HTTP POST are not displayed in the URL.
Variable has no length limit.
$_post and Php://input can be taken to a value, $HTTP _raw_post_data is empty
$_post organizes the submitted data in an associative array and encodes it, such as urldecode, or even coded conversions.
Php://input can obtain unprocessed post raw data by means of input stream as a file read
Php://input allows you to read the original data for the POST. Compared with $HTTP _raw_post_data, it brings less pressure on memory and does not require any special php.ini settings. Php://input cannot be used for enctype= "Multipart/form-data".
Here to expand the Post simulation method
| The code is as follows |
Copy Code |
| ? Php $flag = 0; The data to post $ARGV = Array ( ' var1 ' => ' abc ', ' Var2 ' => ' How are you? ' 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", $errno, $errstr,) or exit ($ERRSTR.) ---> ". $errno); To construct the header of a POST request $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 a Post string $header. = $params. ""; Send the Post data Fputs ($fp, $header); $inheader = 1; while (!feof ($fp)) { $line = fgets ($fp, 1024); Removing the header of the request package shows only the return data of the page if ($inheader && ($line = = "N" | | $line = = "")) { $inheader = 0; } if ($inheader = = 0) { Echo $line; } } Fclose ($FP); ?> |