Home > Article > Backend Development > Example explanation of $_POST in php
$_POST: Array of variables passed via the HTTP POST method. is an automatic global variable.
$GLOBALS['HTTP_RAW_POST_DATA']: Always generate variables containing raw POST data. This variable is only generated when data of an unrecognized MIME type is encountered. $HTTP_RAW_POST_DATA For enctype="multipart/form-data" form data is not available.
That is to say, basically $GLOBALS['HTTP_RAW_POST_DATA'] and $_POST are the same.
But if the posted data is not recognized by PHP, you can use $GLOBALS['HTTP_RAW_POST_DATA'] to receive it, such as text/xml or soap, etc.
Additional explanation: The data type recognized by PHP by default is the application/x-www.form-urlencoded standard data type.
This is what the manual says
Always generate variables containing the original POST
data. Otherwise, this variable is only generated when data of an unrecognized MIME type is encountered. However, a better way to access the raw POST data is
php://input. $HTTP_RAW_POST_DATA for enctype="multipart/form-data"
Form data is not available.
Problem: $HTTP_RAW_POST_DATA == $_POST
?
According to the manual, the answer should be no.
If they are different, what is their difference?
##I know the answer, as follows:
The RAW/uninterpreted HTTP POST
information can be accessed with:
$GLOBALS['HTTP_RAW_POST_DATA']
This is useful in cases where the
post Content-Type is not something PHP understands (such as
text/xml).
That is, basically $GLOBALS['HTTP_RAW_POST_DATA'] and
$_POST is the same. But if the data posted is not recognized by PHP, you can use
$GLOBALS['HTTP_RAW_POST_DATA'] to receive, such as text/xml or soap
etc.
The data type recognized by PHP by default is the application/x-www.form-urlencoded standard data type
Use Content-Type=text/xml
Type, submit an xml document content to the php server, how to obtain this POST data.
The RAW / uninterpreted HTTP POST
information can be accessed with: $GLOBALS['HTTP_RAW_POST_DATA']
This is useful in cases where the post Content-Type is not
something PHP understands (such as text/xml).
Since PHP only recognizes application/x-www.form-urlencoded standard data types by default, it cannot handle content such as text/xml. It is parsed into a $_POST array, so the prototype is retained and passed to $GLOBALS['HTTP_RAW_POST_DATA']
to receive.
There is another item php://input
This function can also be implemented
php://input allows reading the raw data of POST. and
It puts less pressure on memory than $HTTP_RAW_POST_DATA and doesn't require any special php.ini
set up. php://input cannot be used with enctype="multipart/form-data".
application
The above is the detailed content of Example explanation of $_POST in php. For more information, please follow other related articles on the PHP Chinese website!