1:$POST我們常用的就不用介紹了吧
2:$GLOBALS['HTTP_RAW_POST_DATA']:
基本上$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資料。
由于PHP預設隻識别application/x-www.form-urlencoded标準的資料類型,是以,對型如text/xml的内容無法解析為$_POST數組,故保留原型,交給$GLOBALS['HTTP_RAW_POST_DATA'] 來接收。
3:php://input 也可以實作此這個功能:
php://input 允許讀取 POST 的原始資料。和 $HTTP_RAW_POST_DATA 比起來,它給記憶體帶來的壓力較小,并且不需要任何特殊的 php.ini 設定。php://input 不能用于 enctype="multipart/form-data"。
例子:
leyangjun.html
<code><form action=</code><code>"leyangjun.php"</code> <code>method=</code><code>"post"</code><code>></code>
<code><p>First name: <input type=</code><code>"text"</code> <code>name=</code><code>"fname"</code> <code>/></p></code>
<code><p>Last name: <input type=</code><code>"text"</code> <code>name=</code><code>"lname"</code> <code>/></p></code>
<code><input type=</code><code>"submit"</code> <code>value=</code><code>"Submit"</code> <code>/></code>
<code></form></code>
leyangjun.php:
<code>echo</code> <code>"<pre>"</code><code>;</code>
<code>print_r(</code><code>$_POST</code><code>);</code>
<code>echo</code> <code>'<hr />'</code><code>;</code>
<code>$data</code> <code>= </code><code>file_get_contents</code><code>(</code><code>'php://input'</code><code>); //都要解下碼</code>
<code>print_r(urldecode(</code><code>$data</code><code>));</code>
<code>print_r(</code><code>$GLOBALS</code><code>[</code><code>'HTTP_RAW_POST_DATA'</code><code>]);</code>
測試結果:
<a href="http://s3.51cto.com/wyfs02/M02/5B/2C/wKioL1UBTxbilf2RAAFj527yvTQ478.jpg" target="_blank"></a>
End
本文轉自許琴 51CTO部落格,原文連結:http://blog.51cto.com/xuqin/1619751,如需轉載請自行聯系原作者