PHP Post mode _php tutorial

Source: Internet
Author: User
Tags form post

Compare the differences between form post and Fsockopen submission in two different ways.

Form Post Mode submission case

$_post and Php://input can fetch a value, $HTTP _raw_post_data is empty
$_post organizes the submitted data in an associative array, and encodes it, such as UrlDecode, or even transcoding.
Php://input can get unprocessed post raw data via input stream in file read mode

Php://input allows the raw data to be read from the POST. Compared to $HTTP _raw_post_data, it brings less pressure to memory and does not require any special php.ini settings. Php://input cannot be used for enctype= "Multipart/form-data".

Fsockopen Submit Post Data
Cases:

$sock = Fsockopen ("localhost", $errno, $errstr, 30);
if (! $sock) Die ("$errstr ($errno)");
$data = "txt=". UrlEncode ("Medium"). "&bar=". UrlEncode ("Value for Bar");
Fwrite ($sock, "post/posttest/response.php http/1.0");
Fwrite ($sock, "host:localhost");
Fwrite ($sock, "content-type:application/x-www-form-urlencoded");
Fwrite ($sock, "Content-length:".) Strlen ($data). "");
Fwrite ($sock, "Accept: */*");
Fwrite ($sock, "");
Fwrite ($sock, "$data");
Fwrite ($sock, "");
$headers = "";
while ($str = Trim (fgets ($sock, 4096))
$headers. = "$str";
echo "";
$body = "";
while (!feof ($sock))
$body. = Fgets ($sock, 4096);
Fclose ($sock);
Echo $body;

Consistent with (i) results

Conclusion:
1. Php://input can be easily taken to the original post data

2. $HTTP _raw_post_data only valid if the Content-type type of POST is not recognized by PHP

If post data is normally submitted through the page form, it cannot be extracted via $http_raw_post_data. Because of its encoding type attribute (Enctype property) is application/x-www-form-urlencoded, Multipart/form-data.

Note: Even if the Enctype property is explicitly changed within the page to be an unrecognized type for PHP, it is still invalid.
Because the form submission encoding attribute is form-qualified, the unrecognized type is considered to be committed by default encoding (that is, application/x-www-form-urlencoded)

3. $_post is only available when data is submitted by application/x-www-form-urlencoded type.

http://www.bkjia.com/PHPjc/508353.html www.bkjia.com true http://www.bkjia.com/PHPjc/508353.html techarticle compare the differences between form post and Fsockopen submission in two different ways. The form POST method submits the case $_post and php://input can take the value, $HTTP the _raw_post_data is the empty $_post to associate the number ...

  • 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.