CodeIgniter

(Codeigniter) Dynamic base_url() and site_url() Codeigniter 3.0.3 +

For security reason codeigniter 3.0.3 or later $config[‘base_url’] must be configure manually.
check this article -> https://www.codeigniter.com/userguide3/installation/upgrade_303.html

When $config['base_url'] is not set, CodeIgniter tries to automatically detect what your website’s base URL is. This is done purely for convenience when you are starting development of a new application.

Auto-detection is never reliable and also has security implications, which is why you should always have it manually configured!

One of the changes in CodeIgniter 3.0.3 is how this auto-detection works, and more specifically it now falls back to the server’s IP address instead of the hostname requested by the client. Therefore, if you’ve ever relied on auto-detection, it will change how your website works now.

 

But if you still want this work dynamically. you can try this code on \application\config\config.php:

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







You Might Also Like

  • Satya Kresna Adi Pratama

    Thanks mbah coding for your information. I’ve bookmark your article. I hope you always productive to write many articles especially codeigniter or something like web or mobile development. 🙂

  • premkumar k.j

    codeigniter simple server-side datatable example is cannot working codeigniter2.2 how to clear issue???

  • Wahyu Artadianto

    there any one know how to edit if data inside id_number like this “14/5/2017” cause inside my url display http://localhost/master/order//14/5/2017 so ajax think i want to edit id_number with number 2017 there any solution? english or bahasa welcome to answer my problem