PHP $_REQUEST 同名变量解析顺序

$_REQUEST包含了$_GET、$_POST、$_COOKIE的所有内容,是它们的集合体。

但有时$_GET和$_COOKIE有同名变量,或者$_POST和$_COOKIE有同名变量,用$_REQUEST调用变量时从哪里取呢?

其实$_REQUEST解析顺序由variables_order设置,php.ini中原文如下:
This directive describes the order in which PHP registers GET, POST, Cookie, Environment and Built-in variables (G, P, C, E & S respectively, often referred to as EGPCS or GPC). Registration is done from left to right, newer values override older values.

配置如下:
variables_order = “GPCS”

该设置配置PHP解析变量顺序,包括$_GET,$_POST,$_COOKIE,$_ENV ,$_SERVER 数组,解析顺序从左到右,后解析新值覆盖旧值。默认设定为EGPCS(Environment,GET,POST,Cookie,Server)。如果将其设为“GP”,会导致 PHP 完全忽略环境变量,cookies 和 server 变量,并用 POST 方法的变量覆盖 GET 方法的同名变量。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax