php中$_REQUEST一個注意點


問題

說起$_REQUEST,大家都知道的是它是$_GET和$_POST的集合。但是如果你有心的話,查一下文檔,會看到:

$_REQUEST

An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE.

這里說$_REQUEST默認是$_GET, $_POST, $_COOKIE的集合,結果我使用我本地的php查看了一下發現只有$_GET, $_POST, 沒有$_COOKIE!! 難道文檔是錯的?

 

答案

其實changelog中有給出解釋:

clip_image001

版本5.3以上,php.ini中有request_order屬性來設置$_REQUEST。查了下php.ini, request_order設置成為了GP(Get and Post)。

 

request_order的官網描述:

request_order string

This directive describes the order in which PHP registers GET, POST and Cookie variables into the _REQUEST array. Registration is done from left to right, newer values override older values.

If this directive is not set, variables_order is used for $_REQUEST contents.

Note that the default distribution php.ini files does not contain the 'C' for cookies, due to security concerns.

 

原來是G,P,C分別代表Get,Post,Cookie,5.3以上的版本request_order默認是設置成GP的,並不包含C,即$_REQUEST默認只包含$_GET和$_POST !! (所以官網文檔有一定的誤導)。

 

也同時說一下G,P,C的先后順序就是設置的array的覆蓋順序。

提醒下如果你是使用fpm-php實驗的話,改了php.ini后你需要重啟php-fpm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM