$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”); ?>
如何聯絡我:【萬里虎】www.bravetiger.cn
【QQ】3396726884 (諮詢問題100元起,幫助解決問題500元起)
【部落格】http://www.cnblogs.com/kenshinobiy/
相關文章
- GET和POST的區別?
- POST 和 GET 的區別
- GET和POST的區別
- GET 和 POST 的區別
- http和https的區別/get和post的區別HTTP
- get和post區別
- 面試之 get 和 post 區別面試
- HTTP協議類POST 和GET的區別HTTP協議
- http請求之get和post的區別HTTP
- get和post請求的區別(面試)面試
- post與get的區別
- GET 與 POST 的區別
- get與post的區別?
- http請求中get和post方法的區別HTTP
- GET 和 POST 的區別(重要,面試常問)面試
- GET與POST的真正區別
- post、get的區別總結
- GET與POST區別
- GET和POST兩種基本請求方法的區別
- HTTP協議中PUT和POST使用區別HTTP協議
- GET 和 POST 到底有什麼區別?
- ajax 請求的時候 get 和 post 方式的區別?
- get與post的請求區別
- get與post的區別總結
- 淺談HTTP中GET和POST請求方式的區別HTTP
- http協議中,“get”和“post”的區別是什麼HTTP協議
- jquery中$.get()提交和$.post()提交有區別嗎?jQuery
- 程式設計師:我終於知道post和get的區別程式設計師
- get請求和post請求的區別
- POST與GET請求區別
- 一文搞懂 $_POST 和 file_get_contents ("PHP://input") 的區別PHP
- ../和./和/的區別
- HTTP中Get與Post有什麼區別?HTTP
- Python 內建函式:——locals 和 globals介紹Python函式
- Python 兩個內建函式: locals() 和 globals()Python函式
- LinkedList和ArrayList的區別、Vector和ArrayList的區別
- 前後端資料互動(八)——請求方法 GET 和 POST 區別後端
- ||和??的區別
- /*和/**的區別