Home > Back-end >  php post request is empty when posting to url with nginx and switch router
php post request is empty when posting to url with nginx and switch router

Time:11-19

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">&copy; 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.

CodePudding user response:

Your POST is empty, because your <input>s do not have the name='' attribute

  • Related