Let's take a look at two examples first.
Example: Php://input
The code is as follows |
|
<form action= "post.php" method= "POST" > <input type= "text" name= "user" > <input type= "password" name= "password" > <input type= "Submit" > </form> |
post.php
The code is as follows |
|
? Echo file_get_contents ("Php://input");? > |
Example, post
Html
The code is as follows |
|
<form action= "welcome.php" method= "POST" > Enter your name: <input type= "text" name= "name"/> Enter your Age: <input type= "text" name= ' age '/> <input type= "Submit"/> </form> |
welcome.php
The code is as follows |
|
Welcome <?php echo $_post["name"];? >.<br/> are <?php echo $_post["age";?> years old! |
Variables sent over HTTP POST are not displayed in the URL.
When we use $_post to receive the information from the page, we can use Php://input to accept the value, then what is the difference between them?
First, when $_post and php://input can be taken to a value, $http_raw_post_data is null;
$http _raw_post_data is a global variable built into PHP. It is used for PHP, in the case of unrecognized content-type, to fill the post data into the variable $http_raw_post_data. It also fails to read post data that Content-type is multipart/form-data. You need to set the Always_populate_raw_post_data value in php.ini to on,php to always fill in the post data into the variable $http_raw_post_data.
Then $_post the submitted data in an associative array, and encodes it, such as UrlDecode, or even code conversion;
And Php://input obtains the raw post original data through the input stream in the file reading way;
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 can not be used for enctype= "Multipart/form-data";
Php://input cannot read $_get data. This is because the $_get data is written in the path field of the HTTP request header (header) as Query_path, rather than in the body portion of the HTTP request.