Automatic base url

Derek Jones edited this page Jul 5, 2012 · 5 revisions
Clone this wiki locally

Don't you just hate it, when you move from development server to production server that you have to change the $config['base_url'] setting?

Well I do. Because I do it a lot, specially when I'm demoing a web application, that's why I added this code to the config.php

$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

$config['base_url']    = "$root";

Once thats added, Codeigniter base_url will adapt to whatever the url your using. But it won't work if CI launchs from cron