$ _ POST, $ HTTP_RAW_POST_DATA, and php: input can both accept data. Where are the differences between the three? Let's take a look at how this article introduces them. $ _ POST, $ HTTP_RAW_POST_DATA, and php: // input can all accept data. Where are the differences between the three? Let's take a look at how this article describes them.
Script ec (2); script
When PHP 5.6.21 is compiled and installed on Mac Pro, the following warning errors are reported during previous system running:
Deprecated: Automatically populating $ HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. to avoid this warning set 'always _ populate_raw_post_data 'to'-1' in php. ini and use the php: // input stream instead.
The automatic variable $ HTTP_RAW_POST_DATA is out of date and will be removed in the future. Use php: // input stream instead!
Summary: differences between $ _ POST, $ HTTP_RAW_POST_DATA, and PHP: // input
1. HTML
Enctype Attribute
All characters before application/x-www-form-urlencoded is transferred are encoded (spaces are converted to + and special characters are converted to ascii hex)
Multipart/form-data has no character encoded. Generally, upload is used.
Text/plain Spaces is converted to +, but special characters are not encoded.
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
Name = Jonathan + Doe & age = 23 & formula = a + % 2B + B + % 3D % 3D + 13% 25% 21
2. $ _ POST
$ _ POST is the most common method to obtain forms. It organizes submitted data in the form of correlated arrays and performs encoding, such as urldecode and even encoding conversion, recognized data type is PHP default recognized data type application/x-www.form-urlencoded
Non-application/x-www.form-urlencoded data types such as text/xml, application/json, and soap cannot be parsed
3. $ HTTP_RAW_POST_DATA
PHP default recognized data Type is application/x-www.form-urlencoded, with Content-Type = application/json Type, submit the POST data at this time $ _ POST can not be obtained, however, you can obtain it using $ GLOBALS ['HTTP _ RAW_POST_DATA. When PHP cannot identify Content-Type, it will fill in the POST data to $ HTTP_RAW_POST_DATA.
Setting always_populate_raw_post_data in php. ini to On will take effect.
$ HTTP_RAW_POST_DATA is empty when $ _ POST can get the value.
It cannot be used for enctype = "multipart/form-data"
This global variable has been removed from PHP7 and replaced with php: // input. Using always_populate_raw_post_data causes the E_DEPRECATED error when $ HTTP_RAW_POST_DATA is filled. Use php: // input to replace $ HTTP_RAW_POST_DATA because it may be removed from 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 new behaviors.
4. php: // input
Php: // input: You can use the input stream to obtain raw POST data that has not been processed as a file, allowing you to read the original POST data. Compared with $ HTTP_RAW_POST_DATA, it puts less pressure on memory.
No special php. ini settings are required.
It cannot be used for enctype = "multipart/form-data"
Summary
1. If the format is application/x-www-form-urlencoded and multipart/form-data, use $ _ POST;
2. If you cannot obtain text/xml, application/json, or soap, use file_get_contents ('php: // input ');