The difference between $_POST, $HTTP_RAW_POST_DATA, php://input



HTTP_RAW_POST_DATA

Official documentation explains: Native POST data . It needs to be turned on through php.ini. After turning on, the post data can be obtained through the global variable $GLOBALS['HTTP_RAW_POST_DATA'].

  • You need to set the value in php.ini to  always_populate_raw_post_data On to take effect

  • cannot be used with enctype="multipart/form-data"

  • This global variable has been removed in PHP7 and replaced with php://input

  • Requires more memory than php://input


php://input

php://input  accesses individual input/output streams . Allows access to PHP's input and output streams, standard input and output, and error descriptors, in-memory, disk-backed temporary file streams, and filters that can manipulate other read and write file resources. In the case of POST requests, it is better to use php://input  instead of  $HTTP_RAW_POST_DATA , as it does not depend on specific php.ini  directives. Also, in this case  $HTTP_RAW_POST_DATA  is not populated by default,  potentially requiring less memory  than activating always_populate_raw_post_data . php://input  is invalid  when enctype="multipart/form-data"

  • Does not require any special php.ini settings

  • cannot be used with enctype="multipart/form-data"

  • Data acquisition method: $data = file_get_contents("php://input");


$_POST

It can be seen as the data after filtering and formatting $HTTP_RAW_POST_DATA. The recognized data type is the default data type application/x-www.form-urlencoded recognized by PHP

  • Unable to parse content of non-application/x-www.form-urlencoded data types such as text/xml, application/json, etc.

  • Validated cannot be used with enctype="text/plain"   
  • Validated for use with enctype="multipart/form-data"

refer to:

http://php.net/manual/zh/wrappers.php.php

http://www.php.net/manual/zh/reserved.variables.post.php

http://php.net/manual/zh/reserved.variables.httprawpostdata.php


Original address:





HTTP_RAW_POST_DATA

Official documentation explains: Native POST data . It needs to be turned on through php.ini. After turning on, the post data can be obtained through the global variable $GLOBALS['HTTP_RAW_POST_DATA'].

  • You need to set the value in php.ini to  always_populate_raw_post_data On to take effect

  • cannot be used with enctype="multipart/form-data"

  • This global variable has been removed in PHP7 and replaced with php://input

  • Requires more memory than php://input


php://input

php://input  accesses individual input/output streams . Allows access to PHP's input and output streams, standard input and output, and error descriptors, in-memory, disk-backed temporary file streams, and filters that can manipulate other read and write file resources. In the case of POST requests, it is better to use php://input  instead of  $HTTP_RAW_POST_DATA , as it does not depend on specific php.ini  directives. Also, in this case  $HTTP_RAW_POST_DATA  is not populated by default,  potentially requiring less memory  than activating always_populate_raw_post_data . php://input  is invalid  when enctype="multipart/form-data"

  • Does not require any special php.ini settings

  • cannot be used with enctype="multipart/form-data"

  • Data acquisition method: $data = file_get_contents("php://input");


$_POST

It can be seen as the data after filtering and formatting $HTTP_RAW_POST_DATA. The recognized data type is the default data type application/x-www.form-urlencoded recognized by PHP

  • Unable to parse content of non-application/x-www.form-urlencoded data types such as text/xml, application/json, etc.

  • Validated cannot be used with enctype="text/plain"   
  • Validated for use with enctype="multipart/form-data"

refer to:

http://php.net/manual/zh/wrappers.php.php

http://www.php.net/manual/zh/reserved.variables.post.php

http://php.net/manual/zh/reserved.variables.httprawpostdata.php

Original address:
https://blog.csdn.net/kexiaoling/article/details/51858909





HTTP_RAW_POST_DATA

Official documentation explains: Native POST data . It needs to be turned on through php.ini. After turning on, the post data can be obtained through the global variable $GLOBALS['HTTP_RAW_POST_DATA'].

  • You need to set the value in php.ini to  always_populate_raw_post_data On to take effect

  • cannot be used with enctype="multipart/form-data"

  • This global variable has been removed in PHP7 and replaced with php://input

  • Requires more memory than php://input


php://input

php://input 访问各个输入/输出流。允许访问 PHP 的输入输出流、标准输入输出和错误描述符, 内存中、磁盘备份的临时文件流以及可以操作其他读取写入文件资源的过滤器。POST 请求的情况下,最好使用php://input 来代替 $HTTP_RAW_POST_DATA,因为它不依赖于特定的php.ini 指令。 而且,这样的情况下 $HTTP_RAW_POST_DATA 默认没有填充, 比激活always_populate_raw_post_data 潜在需要更少的内存。 enctype="multipart/form-data" 的时候php://input 是无效的

  • 不需要任何特殊的 php.ini 设置

  • 不能用于 enctype="multipart/form-data"

  • 数据获取方式 :$data =  file_get_contents("php://input");


$_POST

可以看成是把$HTTP_RAW_POST_DATA过滤和格式化后的数据。识别的数据类型是PHP默认识别的数据类型 application/x-www.form-urlencoded

  • 无法解析如text/xml,application/json等非 application/x-www.form-urlencoded 数据类型的内容

  • 经验证不能用于enctype="text/plain"   
  • 经验证可用于enctype="multipart/form-data"

参考:

http://php.net/manual/zh/wrappers.php.php

http://www.php.net/manual/zh/reserved.variables.post.php

http://php.net/manual/zh/reserved.variables.httprawpostdata.php

Related Posts