5

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?

4

2 Answers 2

9

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for posting your solution, helped me out.
1

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);

2 Comments

I tried to print out query string, but it is also empty, and the print_r($_GET,1) also has an empty array. I updated the question with my nginx configuration.
Did you try with the .php ? i also compare your Nginx Conf from /etc/nginx/sites-enabled ( i hope its the same path ) . your root path should have root /Users/rweiss/Sites/decaro/LocalOrderWebsite with a / at end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.