'php post request is empty when posting to url with nginx and switch router
So nginx send all the request of the site to the index.php
location / {
try_files $uri $uri/ /index.php;
}
So when I send mine post request to the /login-post as a post request and try to get the post data. The array is always empty and I dont understand what I am missing cause Im posting towards the correct URL? but the post data is not there?
the Form:
<form class="form-signin text-center" action="/login-post" enctype="multipart/form-data" method="post" style="max-width: 400px">
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div style="width: 100%; display: flex; align-content: end; flex-direction: row-reverse;">
<button class="btn btn-lg btn-primary btn-block" style="width: 100px" type="submit">Sign in</button>
</div>
<p class="mt-5 mb-3 text-muted">© 2017-2018</p>
</form>
the php code that should log the post data from (index.php)
$request = $_SERVER['REQUEST_URI'];
echo $request;
switch ($request) {
case '/' :
(new HomeController)->index(); // this works
break;
case '/login' :
(new LoginController())->index(); // this works
break;
case '/login-post':
print_r($_POST); <---- this is always empty
break;
default:
http_response_code(404);
echo "404";
break;
}
I dont see whats going wrong? or why I cant see the post data.
Solution 1:[1]
I had the same issue and I could perform a good solution, the problem is related with the htaccess configuration, so lets try adding this in it
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PROPFIND|PUT) [NC]
RewriteRule .* - [F,L]
It will allow you to preserve the information that you send thru a form
If it does not work please try to change the whole htaccess for something like this
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*) $1.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PROPFIND|PUT) [NC]
RewriteRule .* - [F,L]
RewriteRule ^(.+)$ index.php [QSA,L]
ErrorDocument 404 /404.php
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Steve Romero |
