问题
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?
回答1:
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
回答2:
Try to print out :
echo $_SERVER['QUERY_STRING'];
This is the GET data that is inserted to the Super Global $_GET in addition , i think that you should call to your script using this link :
www.yourdomain.com/service/getAllOrders.php?sortBy=date_created&sortDir=desc
Pay attention to the .php..
See what is at you query string before checking the $_GET , try to print using
echo print_r($_GET,1);
来源:https://stackoverflow.com/questions/27673211/php-get-is-not-populating-with-url-query-parameters-from-web-browser