PHP gets POST JSON data

Source: Internet
Author: User
Tags php source code
Introduction: This is the PHP get post JSON Data detailed page, introduced and php,php, post, json PHP get post JSON data about the knowledge, skills, experience, and some PHP source code and so on.

class= ' pingjiaf ' frameborder= ' 0 ' src= ' http://biancheng.dnbcw.info/pingjia.php?id=359497 ' scrolling= ' no ' >

When passing data through Ajax to a PHP program, it is found that using $_post simply does not get the data. But in the firebug you can see that there is actually JSON data in the post.

After using Print_r (file_get_contents ("Php://input"), the JSON data can be obtained

So what is Php://input?

An introduction to Php://input, the official PHP Handbook document, has a very clear overview of it.

"Php://input allows 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 isn't available with enctype= "Multipart/form-data".

Here's the translation:

"Php://input can read post data that has not been processed. Compared to $http_raw_post_data, it brings less pressure to memory and requires no special php.ini settings. Php://input cannot be used for Enctype=multipart/form-data ".

When the 1,content-type value is application/x-www-form-urlencoded, PHP will fill the HTTP request body with the corresponding data into the array $_post, fill in the $_ The data in the post array is the result of UrlDecode () parsing. (In fact, in addition to the Content-type, there are multipart/form-data that the data is the form data, we will introduce later)

2,php://input data, as long as Content-type is not multipart/form-data (the condition limit is described later). Then PHP: The//input data is consistent with the HTTP entity body part data. The length of the data consistent with this section is specified by Content-length.

3, the $_post data is "consistent" with the Php://input data only if Content-type is application/x-www-form-urlencoded and the method of submission is the Post method (the quotation marks indicate that they are inconsistent in format. Consistent with the content). In other cases, they are inconsistent.

The 4,php://input cannot read $_get data. This is because the $_get data is written as Query_path in the Path field of the HTTP request header (header) instead of the body part of the HTTP request.

I believe we have a certain depth of understanding of php://input. So what is $http_raw_post_data? $http _raw_post_data is a global variable built into PHP. It is used for PHP, in the case of unrecognized content-type, to fill in the variable $http_raw_post_data with the post data. It also fails to read post data that is content-type to Multipart/form-data. You need to set the Always_populate_raw_post_data value in php.ini to on,php to always fill the post data into the variable $http_raw_post_data.

Learn Note 1,coentent-type PHP only fills in the corresponding data in the HTTP request packet into the global variable only if the value is application/x-www-data-urlencoded and multipart/form-data two cases $_post

2,php an unrecognized content-type type, the corresponding data in the HTTP request packet is filled in with the variable $http_raw_post_data

3, only when the coentent-type is not multipart/form-data, PHP will not fill in the HTTP request packet of the corresponding data in the Php://input, otherwise the case will be. The length of the fill, specified by Coentent-length.

4, only Content-type is application/x-www-data-urlencoded, php://input data is consistent with $_post data.

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

6,php will fill in the Query_path portion of the path field into the global variable $_get. Typically, the Get method submits an HTTP request, and the body is empty.

Love EE focus on Java Michael Jackson Video station JSON online tool

Http://biancheng.dnbcw.info/php/359497.html pageno:1
  • 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.