Detailed graphic explanation of the difference between $GLOBALS['HTTP_RAW_POST_DATA'] and $_POST in PHP

墨辰丷
Release: 2023-03-27 06:40:02
Original
2091 people have browsed it

This article mainly introduces the difference between $GLOBALS['HTTP_RAW_POST_DATA'] and $_POST in PHP. It analyzes the functions and usage of $GLOBALS['HTTP_RAW_POST_DATA'] and $_POST based on specific examples. It needs Friends can refer to the

details as follows:

$_POST: An array composed of variables passed through the HTTP POST method. is an automatic global variable.
$GLOBALS['HTTP_RAW_POST_DATA'] : Always generate $HTTP_RAW_POST_DATA variable containing the original POST data. This variable is only generated when data of an unrecognized MIME type is encountered. $HTTP_RAW_POST_DATA is not available for enctype="multipart/form-data" form data.

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 generated only 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 is not available for enctype="multipart/form-data" form data.

Question: Does $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 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..

The data type recognized by PHP by default is the standard data type of application/x-www.form-urlencoded

Use Content-Type=text/xml type to submit the content of an xml document to 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 the application/x-www.form-urlencoded standard data type by default, the content such as text/xml cannot be parsed into the $_POST array, so the prototype is retained. , hand it over to $GLOBALS['HTTP_RAW_POST_DATA'] to receive.

There is also another php://input that can also implement this function

php://input allows reading the original 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".

Application:

a.htm:

<form action="post.php" method="post">
<input type="text" name="user">
<input type="password" name="password">
<input type="submit">
</form>
Copy after login

post.php:

<? echo file_get_contents("php://input"); ?>
Copy after login

Related recommendations:

tomcat configuration php cannot use $_post, $_get

The difference between $_GET and $_POST in PHP

About $_POST in PHP Example explanation

The above is the detailed content of Detailed graphic explanation of the difference between $GLOBALS['HTTP_RAW_POST_DATA'] and $_POST in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!