For an experienced
(1) PHP obtains POST data when the form is submitted in POST mode
$_POST The value can be obtained with php://input, $HTTP_RAW_POST_DATA is empty
$_POST organizes the submitted data in an associative array, and performs encoding processing on it, such as urldecode, and even encoding conversion.
php://input can obtain unprocessed POST raw data through file reading through the input stream
(2) PHP obtains POST data after fsockopen submits POST data
- $sock = fsockopen("localhost", 80,
$errno, $errstr, 30); - if (!$sock) die("$errstr ($errno)n");
-
$data = "txt=" . urlencode("中") .
"&bar =" .urlencode("Value for Bar");
- fwrite($sock, "POST / posttest/response
.php HTTP/1.0rn"); - fwrite($sock, "Host: localhostrn");
- fwrite($sock, "Content-type: applicat
ion/x-www-form-urlencodedrn"); - fwrite($sock, "Content-length: " .
strlen($data) . "rn"); - fwrite($sock, "Accept: */*rn");
- fwrite($sock, "rn");
- fwrite($sock, "$datarn");
- fwrite ($sock, "rn");
-
$headers = ""; >
trim-
(fgets($sock, 4096))) $headers .=
"$strn"-
; echo "n"; >; 🎜>.= fgets
- ($sock, 4096);
-
fclose($sock); echo $body; PHP obtains POST data conclusion:
1. Use php://input to easily get the original POST data - 2. $HTTP_RAW_POST_DATA only when the Content-Type type of POST is not recognized by PHP Valid
For example, POST data usually submitted through page forms cannot be extracted through $HTTP_RAW_POST_DATA. Its encoding type attribute (enctype attribute) is application/x-www-form-urlencoded, multipart/form-data. -
Note: Even if you explicitly change the enctype attribute in the page to a type that is not recognized by PHP, it will still be invalid. Since the form submission encoding attribute is form-limited, unrecognizable types will be considered to be submitted in the default encoding (i.e. application/x-www-form-urlencoded) 3. $_POST only when the data is in application/x PHP can obtain POST data only when the -www-form-urlencoded type is submitted.
http://www.bkjia.com/PHPjc/445978.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445978.htmlTechArticleFor an experienced (1) form POST submission case, PHP gets POST data $_POST with php:/ /input can get the value, $HTTP_RAW_POST_DATA is empty, $_POST is in associative array mode...