thinkphp 5 file_get_contents (php://input) explores ____php

Source: Internet
Author: User
Tags http request
Target

TP out of the new version of 5.0.2 as a TP of the old users, of course, the need for research, in learning TP5 request and response found TP a particularly interesting class request requests. In the constructor class, see today's hero Php://input this thing. First to do a title party, not to study TP5 request class, the study clearly this php://input OK. After all, I have not used this agreement before. Official explanation

PHP provides some miscellaneous input/output (IO) streams that allow access to PHP's input and output streams, standard input and error descriptors, temporary file streams in memory, backup to disk, and filters that can manipulate other reads written to file resources.

Just looking at Php://input

Php://input is a read-only stream that can access the requested raw data. In the case of POST requests, it is best to use php://input instead of $HTTP _raw_post_data because it does not depend on specific php.ini directives. Also, in such cases $HTTP _raw_post_data is not populated by default, and less memory is potentially needed than activating always_populate_raw_post_data. when enctype= "Multipart/form-data", Php://input is ineffective.

Note: Php://input Open data stream can only be read once before PHP 5.6, and the data stream does not support seek operations. However, depending on the SAPI implementation, when the request body data is saved, it can open another php://input data stream and re-read it. Typically, this situation is only for POST requests, not other requests, such as put or PROPFIND.

As you can see from the official website, php://input this input stream is mainly compared with post requests. similarities and differences of Php://input and POST

Contrast a
Client:

<form action= "php_l_input.php" method= "POST"  enctype= "application/x-www-form-urlencoded" >
    name:< Input type= "text" name= "name"/>
    number: <input type= "text" name= "number"/> <input type=
    "Submit" value = "Submit" >
</form>

Service side

Header (' Content-type:text/html;charset=utf-8 ');
$php _input      =   file_get_contents ("Php://input");
Var_dump (($php _input));
Var_dump (UrlDecode ($php _input));
Echo ' 

Results

From above you can see the
(1) When the form is enctype= "application/x-www-form-urlencoded"
(2) method= "POST" of the form

In the above conditions, the two data exactly the same, but the format is different.

... here first omit, back in do edit supplement ...

Summary

Coentent-type only if the value is application/x-www-data-urlencoded and Multipart/form-data two, PHP will fill the HTTP request packet with the corresponding data in the global variable $_post

PHP does not recognize the type of Content-type, the HTTP request package will be filled with the corresponding data in the variable $http_raw_post_data

PHP does not populate the HTTP request packets with the corresponding data in the Php://input unless the coentent-type is multipart/form-data, otherwise it will. The length of the fill, specified by Coentent-length.

Only when Content-type is application/x-www-data-urlencoded, php://input data is consistent with $_post data.

Php://input data is always the same as $http_raw_post_data, but php://input is more effective than $http_raw_post_data and does not require special settings php.ini

PHP fills the query_path portion of the path field into the global variable $_get. Normally, the body is empty for the HTTP request submitted by the Get method.

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.