Search code examples
phpcodeignitercodeigniter-3ngrok

In Codeigniter how to perform POST request through ngrok?


I have a site (using Codeigniter 3.1.10) which is working fine while accessing through localhost. I am trying to test it by accessing it through ngrok, i.e. from another remote system through internet. Through ngrok I am able to access the login page as:

 http://f94181a4.ngrok.io/mysite/logincontroller/login

This displays the login view. However, when I clicked the submit button in the login view/page, it sends POST request as below from the remote systems browser:

http://localhost/mysite/logincontroller/loginaction

Since the remote system is requesting it as http://localhost, it is not able to connect to my local server. So how will I make it to send the POST request with http://f94181a4.ngrok.io when requested from remote system browser.

http://f94181a4.ngrok.io/mysite/logincontroller/loginaction

Solution

  • You probably forgot to set "base_url" config.

    Try to change to this

    $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http";
    $config['base_url'] = "$protocol://{$_SERVER['HTTP_HOST']}/mysite/";