我们先来看两个实例
例子:php://input
代码如下 | |||||
|
post.php
代码如下 | |||||
echo file_get_contents("php://input");?>
|
例子,post
html
代码如下 | |||||
|
welcome.php
代码如下 | |
Welcome . You are years old! |
Variables sent via HTTP POST will not appear in the URL.
When we cannot receive the information from the page using $_POST, we can use php://input to receive the value. So what is the difference between the two?
First, $HTTP_RAW_POST_DATA is empty when $_POST and php://input can get values;
$http_raw_post_data is a global variable built into PHP. It is used by PHP to fill the POST data into the variable $http_raw_post_data as it is when the Content-Type cannot be recognized. It also cannot read POST data whose Content-Type is multipart/form-data. You need to set the always_populate_raw_post_data value in php.ini to On so that PHP will always fill in the POST data into the variable $http_raw_post_data.
Then $_POST organizes the submitted data in an associative array and performs encoding processing, such as urldecode, or even encoding conversion;
And php://input obtains the unprocessed POST original data through file reading through the input stream;
php://input allows reading the raw data of POST. It puts less pressure on memory than $HTTP_RAW_POST_DATA and does not require any special php.ini settings. php://input cannot be used with 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 as query_path, rather than in the body part of the http request.