php中使用$_REQUEST需要注意的一个问题
2017-02-09 16:39
696 查看
问题:说起$_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
$_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
相关文章推荐
- php中使用$_REQUEST需要注意的一个问题
- php中使用$_REQUEST需要注意的一个问题
- php中使用$_REQUEST需要注意的一个问题
- PHP的foreach中使用引用时需要注意的一个问题和解决方法
- PHP的foreach中使用引用时需要注意的一个问题和解决方法
- PHP中使用foreach引用需要注意的问题
- 数组与类使用PHP的可变变量名需要的注意的问题
- 使用string.Format需要注意的一个性能问题
- 使用jQuery Ajax功能的时候需要注意的一个问题
- 使用string.Format需要注意的一个性能问题
- 使用tableViewController时候需要注意的一个问题
- PHP的一个需要注意的POST小问题
- 使用scanf和fgets需要注意的一个小问题
- 使用jQuery Ajax功能的时候需要注意的一个问题
- 调试使用了函数模块的程序时需要注意的一个小问题
- 使用jQuery Ajax功能的时候需要注意的一个问题
- 使用string.Format需要注意的一个性能问题
- 《转》使用jQuery Ajax功能的时候需要注意的一个问题
- 使用jQuery Ajax功能时需要注意的一个问题(内存溢出)
- 调试使用了函数模块的程序时需要注意的一个小问题