CodeIgniter Dynamic base_url


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Determine Subdirectory of Install Path, If Any
  2. // If Not Present, Will Result in /
  3.  
  4. $slash = explode('/', getenv("SCRIPT_NAME"));
  5. $current_filename = $slash[count($slash) - 1];
  6. $host_url = str_replace($current_filename, "", getenv("SCRIPT_NAME"));
  7.  
  8. // If https being used, set base_url to https
  9.  
  10. $http_or_https = (!isset($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) != 'on') ? 'http' : 'https';
  11.  
  12. $config['base_url'] = $http_or_https ."://". $_SERVER['HTTP_HOST'].$host_url;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.