How PHP Gets the raw data for post

Source: Internet
Author: User

Generally we use $_post or $_request two predefined variables to receive post-submitted data. However, if the submitted data does not have a variable name, but rather a direct string, then it needs to be received in other ways.

Method One: Use the global variable $globals[' http_raw_post_data '] to get.

The $globals[' Http_raw_post_data ' store is the raw data that is sent to the POST. $_post or $_request, however, stores the data in PHP in the form of a key=>value format. But whether or not the data in $globals[' Http_raw_post_data ' is saved 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 '].

Method Two: Use File_get_contents ("Php://input") to obtain.

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 most insurance method.

How PHP Gets the raw data for post

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.