天天看點

php中$_REQUEST一個注意點問題答案

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

$_REQUEST

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

這裡說REQUEST預設是REQUEST預設是_GET, POST,POST,_COOKIE的集合,結果我使用我本地的php檢視了一下發現隻有GET,GET,_POST, 沒有$_COOKIE!! 難道文檔是錯的?

其實changelog中有給出解釋:

php中$_REQUEST一個注意點問題答案

版本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預設隻包含REQUEST預設隻包含_GET和$_POST !! (是以官網文檔有一定的誤導)。

也同時說一下G,P,C的先後順序就是設定的array的覆寫順序。

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

本文轉自軒脈刃部落格園部落格,原文連結:http://www.cnblogs.com/yjf512/archive/2012/10/12/2720967.html,如需轉載請自行聯系原作者