Reputation: 3276
I'm trying to access $_POST
and it's empty.
If I try to access it on the root (ie. localhost
), it WORKS.
If I try to access in a different folder (ie. localhost/foo
), it DOESN'T WORK.
Here is my config file:
server {
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name localhost;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Here is a sample RAW request:
POST /dev/post-test HTTP/1.1
Host: localhost
Cache-Control: no-cache
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="action"
store
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="id"
4315251
----WebKitFormBoundaryE19zNvXGzXaLvS5C
What is the problem?
Thanks.
Upvotes: 1
Views: 2473
Reputation: 440
I had same issue - empty $_POST variable.
And found that this happens if a request is sent with this header and the destionation is http instead of https:
Upgrade-Insecure-Requests: 1
In my case I was sending requests from my Unity game to it's server. And it turned out Unity adds that header to all requests sent from the game.
So I had to enable SSL for the server domain and switch from http to https. Once I did that - it worked.
Upvotes: -1
Reputation: 386
The key on this differnet behavier is the trailing slash in the route.
For nginx the following are two different requests:
http://localhost/foo
http://localhost/foo/
The first one result in an internal 301 redirect (to index.php into that folder), where the $_POST values are lost.
More about this behavior and solution to prevent it, read the answers below: Nginx causes 301 redirect if there's no trailing slash
Upvotes: 4