Home > Backend Development > PHP Tutorial > What is the difference between php://input and $_POST in php_PHP tutorial

What is the difference between php://input and $_POST in php_PHP tutorial

WBOY
Release: 2016-07-13 10:39:24
Original
829 people have browsed it

   我们先来看两个实例

  例子:php://input

 代码如下  

 

 
 
 
 

 代码如下  

 

 
 
 
 

  post.php

 代码如下  

 

 代码如下  

 

  例子,post

  html

 代码如下  


Enter your name:
Enter your age:

 代码如下  


Enter your name:
Enter your age:

  welcome.php

 代码如下  
Welcome .

You are years old!

Variables sent via HTTP POST will not appear in the URL.

When we cannot receive the information from the page using $_POST, we can use php://input to receive the value. So what is the difference between the two?

First, $HTTP_RAW_POST_DATA is empty when $_POST and php://input can get values;

 $http_raw_post_data is a global variable built into PHP. It is used by PHP to fill the POST data into the variable $http_raw_post_data as it is when the Content-Type cannot be recognized. It also cannot read POST data whose Content-Type is multipart/form-data. You need to set the always_populate_raw_post_data value in php.ini to On so that PHP will always fill in the POST data into the variable $http_raw_post_data.

Then $_POST organizes the submitted data in an associative array and performs encoding processing, such as urldecode, or even encoding conversion;

And php://input obtains the unprocessed POST original data through file reading through the input stream;

 php://input allows reading the raw data of POST. It puts less pressure on memory than $HTTP_RAW_POST_DATA and does not require any special php.ini settings. php://input cannot be used with 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 as query_path, rather than in the body part of the http request.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/730226.htmlTechArticleLet’s first look at two practical examples: 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 p...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template