当前位置:首页 > PHP教程 > PHP高级教程

PHP中$GLOBALS['HTTP_RAW_POST_DATA']和$_POST的区别分析

本文分析了php中$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"); ?>

更多关于php相关内容感兴趣的读者可查看本站专题:《php字符串(string)用法总结》、《php数组(array)操作技巧大全》、《php基本语法入门教程》、《php运算与运算符用法总结》、《php网络编程技巧总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家php程序设计有所帮助。



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!