Differences between $ POST, $ HTTP_RAW_POST_DATA, and php: // input

Source: Internet
Author: User
Differences between $ POST, $ HTTP_RAW_POST_DATA, and php: input $ POST

$ _ POST is the most commonly used method to obtain POST data. it organizes submitted data in the way of correlated arrays and performs encoding, such as urldecode and even encoding conversion, recognized data type is PHP default recognized data type application/x-www.form-urlencoded

  • Non-application/x-www.form-urlencoded data types such as text/xml and application/json cannot be parsed

HTTP_RAW_POST_DATA

As mentioned above, the default data Type recognized by PHP is application/x-www.form-urlencoded, with Content-Type = application/json Type, the submitted POST data can not be obtained at this time $ _ POST, however, you can obtain it using $ GLOBALS ['http _ RAW_POST_DATA. When PHP cannot identify Content-Type, it will fill in the POST data to $ HTTP_RAW_POST_DATA.

  • It takes effect only when the always_populate_raw_post_data value in php. ini is On.

  • When $ _ POST and php: // input can be obtained, $ HTTP_RAW_POST_DATA is empty.

  • It cannot be used for enctype = "multipart/form-data"

  • This global variable has been removed from php 7 and replaced with php: // input.

Php: // input

Php: // input: you can use the input stream to obtain raw POST data that has not been processed as a file, allowing you to read the original POST data. Compared with $ HTTP_RAW_POST_DATA, it puts less pressure on memory.

  • No special php. ini settings are required.

  • It cannot be used for enctype = "multipart/form-data"

Summary

The above introduces three methods for obtaining POST data using PHP. we can use $ _ POST or PHP: // input to obtain POST data in the future. Although HTTP_RAW_POST_DATA can achieve the same purpose as php: // input, it will put a lot of pressure on the memory. the official team also noticed this problem, so in PHP7, the useless stuff is removed...

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.