PHP input stream php: // input instructions (1/2)

Source: Internet
Author: User
Tags php print

When using xml-rpc, the server obtains client data mainly through the php input stream input instead of the $ _ POST array. So here we will mainly discuss php input stream php: // input

For a php: // input introduction, the PHP official manual provides a clear overview of it.

"Php: // input allows you to read raw POST data. it is a less memory intensive alternative to $ HTTP_RAW_POST_DATA and does not need any special php. ini directives. php: // input is not available with enctype = "multipart/form-data ".

The translation is like this:

"Php: // input can read POST data that has not been processed. Compared with $ HTTP_RAW_POST_DATA, it puts less pressure on memory and does not require special php. ini settings. Php: // input cannot be used for enctype = multipart/form-data"


How should we understand this overview ?! I divided it into three parts and gradually understood it.

Read POST Data
Cannot be used for multipart/form-data Type
Php: // input VS $ HTTP_RAW_POST_DATA
Read POST Data
PHPer must be familiar with the built-in variable $ _ POST. $ _ What are the associations and differences between POST and php: // input? In addition, the most common method for the client to interact with the server is POST and GET. Since php: // input is used as the PHP input stream, can it read GET data? These two questions are what we need to discuss in this section.
Experience tells us that summing up from testing and observation will be a very useful method. Here, I wrote a few scripts to help us test.

@ File 192.168.0.6:/phpinput_server.php print the received data
@ File 192.168.0.8:/phpinput_post.php simulate submitting form data using the POST method
@ File 192.168.0.8:/phpinput_xmlrpc.php simulate the POST method to issue the xmlrpc request.
@ File 192.168.0.8:/phpinput_get.php simulate the number of tables submitted using the GET Method
Phpinput_server.php and phpinput_post.php

 

The Code is as follows: Copy code
<? Php
// @ File phpinput_server.php
$ Raw_post_data = file_get_contents ('php: // input', 'R ');
Echo "------- $ _ POST ------------------ n ";
Echo var_dump ($ _ POST). "n ";
Echo "------- php: // input ------------- n ";
Echo $ raw_post_data. "n ";
?>
 
<? Php
// @ File phpinput_post.php
$ Http_entity_body = 'n' = '. urldecode ('perfgeek').' & amp; p = '. urldecode ('20140901 ');
$ Http_entity_type = 'application/x-www-form-urlencoded ';
$ Http_entity_length = strlen ($ http_entity_body );
$ Host = '1970. 168.0.6 ';
$ Port = 80;
$ Path = '/phpinput_server.php ';
$ Fp = fsockopen ($ host, $ port, $ error_no, $ error_desc, 30 );
If ($ fp ){
Fputs ($ fp, "POST {$ path} HTTP/1.1rn ");
Fputs ($ fp, "Host: {$ host} rn ");
Fputs ($ fp, "Content-Type: {$ http_entity_type} rn ");
Fputs ($ fp, "Content-Length: {$ http_entity_length} rn ");
Fputs ($ fp, "Connection: closernrn ");
Fputs ($ fp, $ http_entity_body. "rnrn ");
 
While (! Feof ($ fp )){
$ D. = fgets ($ fp, 4096 );
}
Fclose ($ fp );
Echo $ d;
}
?>


We can use ngrep to capture http Request packets (because we need to know php: // input, we only capture http Request packets here ). Run the test script phpinput_post.php.

The Code is as follows: Copy code
@ Php/phpinput_post.php
HTTP/1.1 200 OK
Date: Thu, 08 Apr 2010 03:23:36 GMT
Server: Apache/2.2.3 (CentOS)
X-Powered-By: PHP/5.1.6
Content-Length: 160
Connection: close
Content-Type: text/html; charset = UTF-8
------- $ _ POST ------------------
Array (2 ){
["N"] => string (9) "perfgeeks"
["P"] => string (4) "7788"
}
------- Php: // input -------------
N = perfgeeks & p = 7788.

The http Request Packet captured through ngrep is as follows:

T 192.168.0.8: 57846-> 192.168.0.6: 80 [AP]
POST/phpinput_server.php HTTP/1 ..
Host: 192.168.0.6 .. Content-Type: application/x-www-form-urlencoded... Co
Ntent-Length: 18... Connection: close... n = perfgeeks & p = 7788 ....
It is not difficult to find out after careful observation
1, $ _ POST data, php: // the input data is "consistent" with the httpd entity body data
2. the Content-Type in the http request is application/x-www-form-urlencoded, which indicates that the data in the http Request body is the form data submitted using the http post method, and urlencode () is processed.
(Note: note that the content in the bold part will not be prompted below ).

1 2

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.