PHP $ _GET未从Web浏览器填充URL查询参数 [英] PHP $_GET is not populating with URL query parameters, from web browser
本文介绍了PHP $ _GET未从Web浏览器填充URL查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一个奇怪的问题,其中 $ _ GET
(和 $ _ REQUEST
)变量为空,即使参数正在传递。
我的PHP代码:
$ $ p $ echo $ _SERVER ['REQUEST_URI' ]。
echo print_r($ _ REQUEST);
echo print_r($ _ GET);
输出:
/ service / getAllOrders?sortBy = date_created& sortDir = desc
Array()
Array()
我使用nginx并将所有请求转发给index.php。我的配置如下:
server {
listen 80;
server_name decaro.localhost;
root / Users / rweiss / Sites / decaro / LocalOrderWebsite;
#access_log /usr/local/etc/nginx/logs/default.access.log main;
location / {
add_header Cache-Controlno-cache,no-store;
包含/usr/local/etc/nginx/conf.d/php-fpm;
try_files $ uri $ uri / /index.php$args;
}
位置/资产/ {
允许所有;
}
位置= / info {
允许127.0.0.1;
否认所有;
rewrite(。*)/.info.php;
}
error_page 404 /404.html;
error_page 403 / 403.html;
}
为什么?
解决方案是在nginx中传递$ query_string变量:
try_files $ uri $ uri / /index.php?$query_string;
感谢您的全力帮助。
瑞恩
I'm running into a strange issue where the $_GET
(and $_REQUEST
) variable is empty, even though the parameters are being passed.
My PHP code:
echo $_SERVER['REQUEST_URI'];
echo print_r($_REQUEST);
echo print_r($_GET);
Output:
/service/getAllOrders?sortBy=date_created&sortDir=desc
Array()
Array()
I'm using nginx and forwarding all requests to index.php. My configuration is as follows:
server {
listen 80;
server_name decaro.localhost;
root /Users/rweiss/Sites/decaro/LocalOrderWebsite;
#access_log /usr/local/etc/nginx/logs/default.access.log main;
location / {
add_header Cache-Control "no-cache, no-store";
include /usr/local/etc/nginx/conf.d/php-fpm;
try_files $uri $uri/ /index.php$args;
}
location /assets/ {
allow all;
}
location = /info {
allow 127.0.0.1;
deny all;
rewrite (.*) /.info.php;
}
error_page 404 /404.html;
error_page 403 /403.html;
}
Why?
解决方案
The solution was to just pass the $query_string variable in nginx:
try_files $uri $uri/ /index.php?$query_string;
Thanks for all of your help.
Ryan
这篇关于PHP $ _GET未从Web浏览器填充URL查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文