您好,欢迎访问一九零五行业门户网

PHP中$GLOBALS['HTTP_RAW_POST_DATA']和$_POST的区别图文详解

这篇文章主要介绍了php中$globals['http_raw_post_data']和$_post的区别,结合具体实例形式分析了$globals['http_raw_post_data']和$_post的功能与使用过程中的区别,需要的朋友可以参考下
具体如下:
$_post:通过 http post 方法传递的变量组成的数组。是自动全局变量。
$globals['http_raw_post_data'] :总是产生 $http_raw_post_data 变量包含有原始的 post 数据。此变量仅在碰到未识别 mime 类型的数据时产生。$http_raw_post_data 对于 enctype=multipart/form-data 表单数据不可用。
也就是说基本上$globals['http_raw_post_data'] 和 $_post是一样的。
但是如果post过来的数据不是php能够识别的,你可以用 $globals['http_raw_post_data']来接收,比如 text/xml 或者 soap 等等。
补充说明:php默认识别的数据类型是application/x-www.form-urlencoded标准的数据类型。
这是手册里写的:
总是产生变量包含有原始的 post 数据。否则,此变量仅在碰到未识别 mime 类型的数据时产生。不过,访问原始 post 数据的更好方法是 php://input。$http_raw_post_data 对于 enctype=multipart/form-data 表单数据不可用。
问题: $http_raw_post_data == $_post 吗?
照手册所写 ,答案应该就为否。
假如不一样的话,他们的区别是什么呢?
我知道答案了,如下:
the raw / uninterpreted http post information can be accessed with:
$globals['http_raw_post_data']
this is useful in cases where the post content-type is not something php understands (such as text/xml).
也就是说,基本上$globals['http_raw_post_data'] 和 $_post是一样的。但是如果post过来的数据不是php能够识别的,你可以用 $globals['http_raw_post_data']来接收,比如 text/xml 或者 soap 等等。
php默认识别的数据类型是application/x-www.form-urlencoded标准的数据类型
用content-type=text/xml 类型,提交一个xml文档内容给了php server,要怎么获得这个post数据。
the raw / uninterpreted http post information can be accessed with: $globals['http_raw_post_data'] this is useful in cases where the post content-type is not something php understands (such as text/xml).
由于php默认只识别application/x-www.form-urlencoded标准的数据类型,因此,对型如text/xml的内容无法解析为$_post数组,故保留原型,交给$globals['http_raw_post_data'] 来接收。
另外还有一项 php://input 也可以实现此这个功能
php://input 允许读取 post 的原始数据。和 $http_raw_post_data 比起来,它给内存带来的压力较小,并且不需要任何特殊的 php.ini 设置。php://input 不能用于 enctype=multipart/form-data。
应用:
a.htm:
<form action="post.php" method="post"> <input type="text" name="user"> <input type="password" name="password"> <input type="submit"> </form>
post.php:
<? echo file_get_contents("php://input"); ?>
相关推荐:tomcat配置php无法使用$_post、$_get
php中$_get与$_post的区别
php中关于$_post的实例讲解
以上就是php中$globals['http_raw_post_data']和$_post的区别图文详解的详细内容。
其它类似信息

推荐信息