$_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"); ?>
如何聯系我:【萬裡虎】www.bravetiger.cn
【QQ】3396726884 (咨詢問題100元起,幫助解決問題500元起)
【部落格】http://www.cnblogs.com/kenshinobiy/