CodeIgniter Forums
Post is always empty on live server - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Post is always empty on live server (/showthread.php?tid=80332)



Post is always empty on live server - SteeveDroz - 10-18-2021

Hello,
I put up my website on the prod server and there way the following problem:
When sending a form with method POST, nothing is received in the controller.


Informations:
  • When checking the developper tools of my browser, I see the request is sent with the correct method (POST) and the data are present.
  • When writing
    Code:
    var_dump($this->request->getPost())
    or
    Code:
    var_dump($_POST)
    in the controller, an empty array is displayed.
  • If I try to do the same request with Postman, the result is the same.
  • When trying a simple PHP page that doesn't use the Framework, everything works fine ⇒ it's probably CodeIgniter's fault (or, more plausibly, my configuration).
  • Everything Works Fine on My Machine™, but it doesn't in the server (well, the rest does, only the POST content is lost AFAIK).
  • The server is hosted by OVH.
  • The code has been tested with both PHP 7.4 and PHP 8.0.
Any chance one of you knows what I'm talking about and has a solution to explain? I'm willing to provide extended informations upon demand.

Thanks to whoever takes some time to answer!


RE: Post is always empty on live server - InsiteFX - 10-19-2021

If you want help on this then you need to post your controller and html form code here for us to look at.


RE: Post is always empty on live server - SteeveDroz - 10-19-2021

Here is my code:

The HTML code:


Code:
<form method="post" class="table">
    <label for="email">Adresse email</label>
    <input type="email" name="email" id="email" value="{email}" autofocus>
    <div>{+validation_errors field=email+}</div>
    <label for="password">Mot de passe</label>
    <input type="password" name="password" id="password">
    <div>{+validation_errors field=password+}</div>
    <button class="full-width">Se connecter</button>
</form>

The controller (method User::login):


PHP Code:
    public function login()
    {
        var_dump($this->request->getPost()); // array(0) { }
        var_dump($_POST); // array(0) { }
        $login $this->request->getPost();

        if ($this->request->getMethod() == 'post') {
            if ($this->validate('login')) {
                $this->auth->login($login);
                return redirect()->to('/');
            }
        }
        $this->useTables();
        $this->data['email'] = $login['email'] ?? '';
        $this->render();
    



RE: Post is always empty on live server - InsiteFX - 10-19-2021

Your missing the action attribute.

PHP Code:
<form action="/controller/method" method="post"



RE: Post is always empty on live server - SteeveDroz - 10-19-2021

Additional information:

It seems that the response is sent twice, for example, if I contact the page with curl, I get 2 ci-session cookies.

I know that has been talked about on this forum before, but I checked all the potential missing links, nothing seems wrong.

(10-19-2021, 02:25 AM)InsiteFX Wrote: Your missing the action attribute.

PHP Code:
<form action="/controller/method" method="post"

No, if action is missing, the PHP_SELF page is used. It can't be that because the page is correctly displayed after the form is sent.

Other new information:

Code:
curl -i https://cramine.ch
returns HTTP/2 200

Code:
curl -I https://cramine.ch
returns HTTP/2 404


RE: Post is always empty on live server - SteeveDroz - 10-19-2021

The response was indeed sent twice. I am using a composer package that didn't adapt to the latest versions of CodeIgniter. I notified the developper and manually edited vendor in the meantime.

Thanks for all your help!