Why PHP can only accept the post value not received by get

Source: Internet
Author: User
PHP generally use GET or post value, this article is mainly to share with you why PHP can only accept get receive not post value, hope to help everyone.

A few ways to get post data from PHP

Method 1, the most common method is: $_post[' fieldname '];

Note: only data submitted by content-type:application/x-www-form-urlencoded can be received
Explanation: That is, the data that forms post

Method 2, File_get_contents ("Php://input");

Description
Allows the raw data to be read from the POST.

(This method is only used when testing the tool with the interface if the header is set to Content-type:application/json. )
Compared to $HTTP _raw_post_data, it brings less pressure to memory and does not require any special php.ini settings.
Php://input cannot be used for enctype= "Multipart/form-data".
Explain:
For post data that does not specify Content-type, you can use File_get_contents ("Php://input") to get the raw data.
In fact, this method can be used for any data that is received by the post in PHP. Regardless of the Content-type, including binary file streams is also possible.
So using method Two is the safest method.

Method 3, $GLOBALS [' Http_raw_post_data '];

Description:
always produces $HTTP the _raw_post_data variable contains the original POST data.
This variable is only generated when you encounter data with an unrecognized MIME type.
$HTTP _raw_post_data is not available for enctype= "multipart/form-data" form data
If the data you POST is not recognized by PHP, you can use $GLOBALS [' Http_raw_ Post_data '] to receive,
such as text/xml or soap, and so on
Explanation: the
$GLOBALS [' Http_raw_post_data '] holds the raw data that came in POST.
$_post or $_request holds PHP in the form of a key=>value format for subsequent data.
But whether or not to save post data in $globals[' Http_raw_post_data '] depends on the settings of the Centent-type, that is, the post data must be explicitly indicated content-type:application/ X-www-form-urlencoded,post data is stored in the $GLOBALS [' Http_raw_post_data '].

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.