$ _POST Receive data
$ _POST Is an array variable is passed by way of HTTP POST method consisting of automatic global variable. Such as using $ _POST ['name'] you can receive a web form and web data asynchronously over the post, namely $ _POST can only receive a document type Content-Type: application / data x-www-form-urlencoded submitted.
$ GLOBALS ['HTTP_RAW_POST_DATA'] receive data
If the data is not used over the post PHP can identify the type of document, such as text / xml or soap, etc., we can receive with $ GLOBALS ['HTTP_RAW_POST_DATA']. Populate the $ HTTP_RAW_POST_DATA containing the raw POST data. This variable is generated only when confronted with unrecognized MIME type of the data. $ HTTP_RAW_POST_DATA for enctype = "multipart / form-data" form data is not available. That use of $ HTTP_RAW_POST_DATA can not receive data over the web form post.
php: // input receive data
If a better way to access the raw POST data is php: // input. php: // input allows you to read raw POST data. It brings to memory and $ HTTP_RAW_POST_DATA less pressure than, and does not require any special php.ini settings and php: // input can not be used enctype = "multipart / form-data".
For example, the user uses a client application to post a document, the contents of the file server does not concern us, but we want to complete this file is saved on the server, we can use the following code:
$input = file_get_contents('php://input'); file_put_contents($original, $input); //$original is in server
The above code uses file_get_contents ('php: // input') receiving post data, and then the data is written to $ original document, in fact, can be understood from the client to upload a file to the server, this type of application is very large, especially we will use PHP development to the C, C ++ and other application development jointly developed product, such as uploading pictures that combine flash use this principle to upload photos.
The following is a small example that illustrates $ _POST, $ GLOBALS ['HTTP_RAW_POST_DATA'] and php: // input in three different ways to receive POST data processing:
<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>
header("Content-type:text/html;charset=utf-8"); echo '$_POST receive:<br/>'; print_r($_POST); echo '<hr/>'; echo '$GLOBALS[\'HTTP_RAW_POST_DATA\']reveive:<br/>'; print_r($GLOBALS['HTTP_RAW_POST_DATA']); echo '<hr/>'; echo 'php://input receive:<br/>'; $data = file_get_contents('php://input'); print_r(urldecode($data));