Typically, users use a browser Web page form to submit data to the server post, and we use PHP to receive data from the user post to the server and to handle it appropriately. But in some cases, if the user uses the client software to send post data to the server-side PHP program, instead of using $_post to identify, then how to deal with it?
Receive data in $_post mode
The $_post method is an array of variables passed through the HTTP POST method, and is an automatic global variable. If you use $_post[' name ', you can receive a Web page form and the data that the Web page asynchronously posts, that is, $_post can only receive document type content-type:application/ Data submitted by x-www-form-urlencoded.
Receive Data $GLOBALS [' Http_raw_post_data ']
If the data that was posted is not the type of document that PHP can recognize, such as text/xml or soap, we can receive it with $globals[' Http_raw_post_data '. The $HTTP _raw_post_data variable contains the original POST data. This variable is generated only when data with an unrecognized MIME type is encountered. $HTTP _raw_post_data is not available for enctype= "multipart/form-data" form data. That is, you cannot receive data from a Web Form POST by using $http_raw_post_data.
Receive data in Php://input mode
A better way to access the original POST data is php://input. Php://input allows you to read the original data for the POST. Compared with $HTTP _raw_post_data, it brings less pressure on memory and does not require any special php.ini settings, and php://input cannot be used enctype= "Multipart/form-data".
For example, a user uses a client application to post to the server a file, the contents of the file we ignore it, but we want to keep this file on the server completely, we can use the following code:
$input = file_get_contents (' php://input ');
File_put_contents ($original, $input); $original to files on the server
The above code uses file_get_contents (' Php://input ') to receive post data, and then writes the data to the $original file, which can actually be understood as uploading a file from the client to the server, such applications are very many, In particular, our PHP development will be used with c,c++ and other application development for product joint development.
The following is a small example that demonstrates $_post, $GLOBALS [' Http_raw_post_data '] and php://input three different ways of receiving POST data processing:
A.html
<form name= "Demo_form" action= "post.php" method= "POST" >
<p><label>name: </label>< Input type= "text" class= "input" name= "name" ></p>
<p><label>address: </label>< Input type= "text" class= "input" name= "address" ></p>
<p><input type= "Submit" name= "Submit" class= "btn" value= "Submit" ></p>
</form>
post.php
Header ("Content-type:text/html;charset=utf-8");
Echo ' $_post receive:<br/> ';
Print_r ($_post);
Echo '
The above is the entire content of this article, I hope you can receive the post data in PHP 3 ways to know something.