Home » Php » php – How to set Dynamic base url to https in CodeIgniter?

php – How to set Dynamic base url to https in CodeIgniter?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I try the use a dynamic base url in this post:

Set Dynamic Base Url in CodeIgniter

But I used to be use the http, but now, I would like to change to https, how can I do so? Thanks.

How to&Answers:

In your config/config.php, try this:

$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;

Answer:

You can use codeigniter hooks in pre_controller you just change the base_url http to https by string replace and set the base url

Answer:

$config[‘base_url’] = (isset($_SERVER[‘HTTPS’]) ? “https://” : “http://”).$_SERVER[‘HTTP_HOST’];

this works for me with virtualhost setup.