PHP Fsockopen submit the post data to explain

Source: Internet
Author: User
Tags form post urlencode

Comparison form [Url=javascript:;] Post[/url] and Fsockopen submit two different ways of difference.

Form Post Mode submission case
$_post and [url=javascript:;] Php[/url]://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/resp****e.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 the Content-type type in the POST is not PHPOnly valid when recognized
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.
Plus-.S. HTMLThe search is considered a static page pull.

PHP Fsockopen submit the post data to explain

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.