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.
2
Answers
Your POST is empty, because your
<input>
s do not have thename=''
attributeI 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
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