$HTTP_RAW_POST_DATA

這是手冊裏寫的

老是產生變量包含有原始的 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"。 


應用 

php


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");   ?>  
數組

相關文章
相關標籤/搜索