Php://input and $ in PHP

Source: Internet
Author: User
Tags http post http request ini

Let's take a look at two examples first.

Example: Php://input

The code is as follows

<form action= "post.php" method= "POST" >
<input type= "text" name= "user" >
<input type= "password" name= "password" >
<input type= "Submit" >
</form>

post.php

The code is as follows

? Echo file_get_contents ("Php://input");? >

Example, post

Html

The code is as follows

<form action= "welcome.php" method= "POST" >
Enter your name: <input type= "text" name= "name"/>
Enter your Age: <input type= "text" name= ' age '/>
<input type= "Submit"/>
</form>

welcome.php

The code is as follows
Welcome <?php echo $_post["name"];? >.<br/>
are <?php echo $_post["age";?> years old!

Variables sent over HTTP POST are not displayed in the URL.

When we use $_post to receive the information from the page, we can use Php://input to accept the value, then what is the difference between them?

First, when $_post and php://input can be taken to a value, $http_raw_post_data is null;

$http _raw_post_data is a global variable built into PHP. It is used for PHP, in the case of unrecognized content-type, to fill the post data into the variable $http_raw_post_data. It also fails to read post data that Content-type is multipart/form-data. You need to set the Always_populate_raw_post_data value in php.ini to on,php to always fill in the post data into the variable $http_raw_post_data.

Then $_post the submitted data in an associative array, and encodes it, such as UrlDecode, or even code conversion;

And Php://input obtains the raw post original data through the input stream in the file reading way;

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

Php://input cannot read $_get data. This is because the $_get data is written in the path field of the HTTP request header (header) as Query_path, rather than in the body portion of the HTTP request.

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.