Three ways to get post data from PHP

Source: Internet
Author: User
method One, $_post

$_post or $_request is stored in PHP in the form of key=>value format after the data.

method Two, using file_get_contents ("Php://input")

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 is used for any data received by the post in PHP. Without considering Content-type, including binary file streams is also possible.
Compared to $http_raw_post_data, it brings less pressure to memory and does not require any special php.ini settings.
Php://input cannot read the post data content-type is multipart/form-data, you need to set the Always_populate_raw_post_data value in php.ini to ON.
Php://input the _get data is not read. is because the $_get data is written as Query_path in the HTTP request header (header) of the path field, rather than written in the body portion of the HTTP request.

method Three, use global variable $globals[' http_raw_post_data ']

In $globals[' Http_raw_post_data ') The original data is stored in the POST.
However, whether or not to save the POST data in $globals[' http_raw_post_data '] depends on the settings of the Centent-type, only if PHP is in an unrecognized content-type condition. The POST data is filled in the variable $globals[' Http_raw_post_data '], like content-type=application/x-www-form-urlencoded, The variable is empty.
In addition, it is also unable to read the post data of Content-type to Multipart/form-data, but also to set the Always_populate_raw_post_data value in php.ini to ON, PHP will always fill in the post data into the variable $http_raw_post_data.

Three kinds, PHP, POST
  • Related Article

    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.