Php obtains POSTJSON data

Source: Internet
Author: User
Introduction to php post json data acquisition: this is a detailed page for php to obtain post json data. it introduces the knowledge, skills, and experience related to php, php, POST, and JSON php to obtain post json data, and some php source code.

Class = 'pingjiaf' frameborder = '0' src = 'http: // biancheng.dnbc?info/pingjia.php? Id = 359497 'Rolling = 'no'>

When passing data to the php program through ajax, we will find that $ _ POST cannot be used to obtain data at all. However, in firebug, we can see that post contains json data.

After print_r (file_get_contents ("php: // input") is used, json data is obtained.

So what is php: // input?

For introduction to php: // input, the PHP official manual provides a clear overview of it.

"Php: // input allows you to read raw POST data. it is a less memory intensive alternative to $ HTTP_RAW_POST_DATA and does not need any special php. ini directives. php: // input is not available with enctype = "multipart/form-data ".

The translation is like this:

"Php: // input can read POST data that has not been processed. Compared with $ HTTP_RAW_POST_DATA, it puts less pressure on memory and does not require special php. ini settings. Php: // input cannot be used for enctype = multipart/form-data ".

1. when the value of Content-Type is application/x-www-form-urlencoded, php will fill in the corresponding data of the http request body to the array $ _ POST, the data filled in the $ _ POST array is the result of urldecode () parsing. (In fact, in addition to the Content-Type, there is also multipart/form-data indicating that the data is form data. we will introduce it later)

2, php: // input data, as long as the Content-Type is not multipart/form-data (this condition will be described later ). Php: // the input data is consistent with the part of the http entity body. The consistent data Length is specified by Content-Length.

3. only when the Content-Type is application/x-www-form-urlencoded and the submission method is POST, $ _ POST data and php: // the input data is "consistent" (with quotation marks, indicating that the formats are inconsistent and the content is consistent. In other cases, they are inconsistent.

4. php: // input cannot read $ _ GET data. The reason is that the $ _ GET data is written in the PATH field of the http request header as query_path, rather than in the http request body.

I believe you have a deep understanding of php: // input. So what is $ http_raw_post_data? $ Http_raw_post_data is a built-in global variable in PHP. It is used by PHP to replace the POST data with the variable $ http_raw_post_data without recognizing the Content-Type. It cannot read POST data whose Content-Type is multipart/form-data. You need to set the always_populate_raw_post_data value in php. ini to On, and PHP will always fill in the POST data with the variable $ http_raw_post_data.

Study note 1, Coentent-Type only when the value is application/x-www-data-urlencoded and multipart/form-data, PHP will fill in the corresponding data in the http request packet with the global variable $ _ POST

2. when PHP cannot recognize the Content-Type, it will fill in the corresponding data in the http request package with the variable $ HTTP_RAW_POST_DATA

3. when the Coentent-Type is not multipart/form-data, PHP will not fill in the corresponding data in the http request packet in php: // input; otherwise, it will be used in other cases. Length specified by Coentent-Length.

4. php: // input data is consistent with $ _ POST data only when the Content-Type is application/x-www-data-urlencoded.

5. php: // the input data is always the same as $ HTTP_RAW_POST_DATA, but php: // the input data is more efficient than $ HTTP_RAW_POST_DATA, and php. ini does not require special settings.

6. PHP will fill in the query_path section of the PATH field with the global variable $ _ GET. Normally, the http request submitted by the GET method has no body.

Love J2EE follow Java Michael Jackson video station JSON online tools

Http:// pageNo: 1.

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: 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.