Home >Backend Development >PHP Tutorial >【PHP】$_POST, $HTTP_RAW_POST_DATA, and php://input,httprawpostdata_PHP教程
For example, the key-value pairs
name: Jonathan Doe age: 23 formula: a + b == 13%!
are encoded as the following raw data:
name=Jonathan+Doe&age=23&formula=a+%2B+b+%3D%3D+13%25%21
$_POST
Array ( [name] => Jonathan Doe [age] => 23 [formula] => a + b == 13%! )
$HTTP_RAW_POST_DATA
print_r($GLOBALS['HTTP_RAW_POST_DATA'] ); name=Jonathan+Doe&age=23&formula=a+%2B+b+%3D%3D+13%25%21
php://input
$post_data = file_get_contents('php://input'); print_r($post_data); name=Jonathan+Doe&age=23&formula=a+%2B+b+%3D%3D+13%25%21
$_POST is the most commonly used way to obtain a form. It organizes the submitted data in an associative array and performs encoding processing, such as urldecode, or even encoding conversion. The recognized data type is the data type recognized by PHP by default. application/x-www.form-urlencoded
Unable to parse content such as text/xml, application/json and other non-application/x-www.form-urlencoded data types
The data type recognized by PHP by default is application/x-www.form-urlencoded, use Content-Type=application/json type, the submitted POST data $_POST cannot be obtained at this time, but use $GLOBALS['HTTP_RAW_POST_DATA '] can be obtained. Because when PHP cannot recognize the Content-Type, it will fill in the POST data into $HTTP_RAW_POST_DATA.
Set the always_populate_raw_post_data
value in php.ini to On to take effect
When $_POST and php://input can get the value, $HTTP_RAW_POST_DATA is empty
cannot be used with enctype="multipart/form-data"
This global variable has been removed in PHP7 and replaced with php://input. Using always_populate_raw_post_data will cause errors when filling in $HTTP_RAW_POST_DATAE_DEPRECATED
. Please use php://input instead of $HTTP_RAW_POST_DATA as it may be removed in subsequent PHP versions. Set always_populate_raw_post_data to -1 (this will force $HTTP_RAW_POST_DATA to be undefined, so it will not cause E_DEPRECATED
errors) to experience the new behavior.
php://input can obtain unprocessed POST raw data through file reading through the input stream, allowing reading of POST raw data. It puts less pressure on memory than $HTTP_RAW_POST_DATA.
No special php.ini settings required
cannot be used with enctype="multipart/form-data"