$ _GET已填满,但$ _REQUEST为空

时间:2014-02-07 08:16:28

标签: php nginx

我最近在Windows 7中安装了nginx 1.4.4和PHP 5.5.8。我运行nginx.exe和php-cgi.exe来运行服务器并运行。当我在网址中发送查询字符串时,如果我print_r($_GET) 从查询字符串中获得值。但是,如果我print_r($_REQUEST)$_REQUEST只是空数组。我在stackoverflow中已经关注了一些其他问题,我发现只是检查request_order和variables_order。在php.ini中 这是我在php.ini中对request_order和variables_order的当前配置:

; This directive determines which super global arrays are registered when PHP
; starts up. G,P,C,E & S are abbreviations for the following respective super
; globals: GET, POST, COOKIE, ENV and SERVER. There is a performance penalty
; paid for the registration of these arrays and because ENV is not as commonly
; used as the others, ENV is not recommended on productions servers. You
; can still get access to the environment variables through getenv() should you
; need to.
; Default Value: "EGPCS"
; Development Value: "GPCS"
; Production Value: "GPCS";
; http://php.net/variables-order
variables_order="GPCS"

; This directive determines which super global data (G,P,C,E & S) should
; be registered into the super global array REQUEST. If so, it also determines
; the order in which that data is registered. The values for this directive are
; specified in the same manner as the variables_order directive, EXCEPT one.
; Leaving this value empty will cause PHP to use the value set in the 
; variables_order directive. It does not mean it will leave the super globals
; array REQUEST empty.
; Default Value: None
; Development Value: "GP"
; Production Value: "GP"
; http://php.net/request-order
request_order="GP"

我还找到了关闭auto_globals_jit的答案,但它不起作用。 我有一个正在安装的xampp 1.8.3,它在apache服务器上运行。但是当nginx使用xampp的PHP时,$_REQUEST也是空的。

有些文章告诉我们更改nginx配置以在fastcgi_params中添加query_string。但情况是$_SERVER['QUERY_STRING']是空的。但就我而言,$_SERVER['QUERY_STRING']包含值。我仍在尝试,但它也不起作用。

还缺少什么?谢谢。

修改

这是我的nginx服务器配置(我使用Code Igniter,所以我按照http://wiki.nginx.org/Codeigniter进行配置:

server {
    listen       80;
    server_name  local.dev.com;
    root   html/dev;
    autoindex on;
    index index.php;

    location / {

        try_files $uri $uri/ /index.php;

        location = /index.php {

            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  QUERY_STRING       $query_string;
            fastcgi_param  SCRIPT_FILENAME D:/nginx/html/dev$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

    location ~ \.php$ {
        return 444;
    }
}

1 个答案:

答案 0 :(得分:0)

当使用协议 REQUEST_URI 自动(请参阅$_GET)时,CodeIgniter会从$_SERVER['REQUEST_URI']手动构建$config['uri_protocol']

你应该修改nginx的配置,替换line:

try_files $uri $uri/ /index.php;

 try_files $uri $uri/ /index.php$is_args$args;

解决空$_REQUEST

的问题