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.