Analysis of the difference between $_post and php://input in PHP _php techniques

Source: Internet
Author: User
Tags http post

This article analyzes the difference between $_post and Php://input in PHP. Share to everyone for your reference. The specific analysis is as follows:

$_post and PHP Tutorials://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 coded conversions
Php://input can also implement this feature to get the original data for the post.
Code

Copy Code code as follows:
Echo file_get_contents ("Php://input");

instance
Copy Code code as follows:
<form action= "post.php" method= "POST" >
<input type= "text" name= "user" >
<input type= "password" name= "password" >
<input type= "Submit" >
</form>

post.php
Copy Code code as follows:
? Echo file_get_contents ("Php://input");? >


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 cannot be used for enctype= "Multipart/form-data".

PHP's $_post:

The $_post variable is an array of variable names and values that are sent by the HTTP POST method.

The $_post variable is used to collect values from the form in the method= "post", and the information sent from the form with the Post method is not visible to anyone (not shown in the browser's address bar), and there is no limit to the amount of information sent.

Html

Copy Code code 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
Copy Code code 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, and the variable has no length limit.

I hope this article will help you with your PHP program design.

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.