程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> php中使用$_REQUEST需要注意的一個問題

php中使用$_REQUEST需要注意的一個問題

編輯:PHP綜合

問題
說起$_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中有給出解釋:

版本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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved