Compare two different methods of form [urljavascript:;] POST [/url] and fsockopen commit. When the form POST method is submitted, $ _ POST and [urljavascript:;] php [/url]: // input can get the value, $ HTTP_RAW_POST_DATA is empty $ _ POST organizes submitted data in the joined array mode, and compares the data in the form [url = javascript:;] POST [/url] and fsockopen submit are different methods.
When the form POST method is submitted
$ _ POST and [url = javascript:;] php [/url]: // input can get the value, $ HTTP_RAW_POST_DATA is blank
$ _ POST organizes submitted data in an associated array and performs encoding, such as urldecode or even encoding conversion.
Php: // input: raw POST data that has not been processed can be obtained by reading files from the input stream.
Php: // input allows reading original POST data. Compared with $ HTTP_RAW_POST_DATA, it puts less pressure on the memory and does not require any special php. ini settings. Php: // input cannot be used for enctype = "multipart/form-data ".
Fsockopen submits POST data
Example:
$ Sock = fsockopen ("localhost", 80, $ 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 (1) Results
Conclusion:
1. you can use php: // input to conveniently retrieve the original POST data.
2. $ HTTP_RAW_POST_DATA is valid only when the POST Content-Type is not recognized by PHP.
For example, the POST data submitted through the page form cannot be extracted through $ HTTP_RAW_POST_DATA. The encoding type attribute (enctype attribute) is application/x-www-form-urlencoded and multipart/form-data.
Note: Even if the enctype attribute is explicitly changed to an unrecognized PHP type on the page, it still does not work.
Because the form submission encoding attribute is a form limitation, unrecognized types are considered to be submitted in the default encoding mode (application/x-www-form-urlencoded)
3. $ _ POST is only available when data is submitted by application/x-www-form-urlencoded type.
With -.shtml, search is regarded as static page pulling.
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.