Home > Backend Development > PHP Tutorial > Introducing several PHP techniques for obtaining POST data_PHP tutorial

Introducing several PHP techniques for obtaining POST data_PHP tutorial

WBOY
Release: 2016-07-15 13:34:36
Original
1046 people have browsed it

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

  1. $sock = fsockopen("localhost", 80,
    $errno, $errstr, 30);
  2. if (!$sock) die("$errstr ($errno)n");
  3. $data = "txt=" . urlencode("中") .
    "&
    bar =" .urlencode("Value for Bar");
  4. fwrite($sock, "POST / posttest/response
    .php HTTP/1.0rn");
  5. fwrite($sock, "Host: localhostrn");
  6. fwrite($sock, "Content-type: applicat
    ion/x-www-form-urlencodedrn");
  7. fwrite($sock, "Content-length: " .
    strlen($data) . "rn");
  8. fwrite($sock, "Accept: */*rn");
  9. fwrite($sock, "rn");
  10. fwrite($sock, "$datarn");
  11. fwrite ($sock, "rn");
  12. $headers = ""; >
  13. trim
  14. (fgets($sock, 4096))) $headers .=
  15. "$strn"
  16. ; echo "n"; >; 🎜>.= fgets
  17. ($sock, 4096);
  18. fclose($sock); echo $body; PHP obtains POST data conclusion:
  19. 1. Use php://input to easily get the original POST data
  20. 2. $HTTP_RAW_POST_DATA only when the Content-Type type of POST is not recognized by PHP Valid
  21. 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.
  22. 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.

    www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template