CodeIgniter Dynamic base_url

#saturday, 11th february 2012 at 05:31am

Categories : Tips and Tricks

As CodeIgniter user myself, it is often part of my every CI-Based projects to have set base_url dynamically:

if(isset($_SERVER['HTTP_HOST']))
{
$config['base_url'] = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$config['base_url'] .= '://'. $_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
else
{
$config['base_url'] = 'http://localhost/';
}

Categories

Widget Error

The Weather feed URL is not reachable
http://weather.yahooapis.com/forecastrss?w=1177694&u=c

Widget Error

The Weather feed URL is not reachable
http://feeds.howstuffworks.com/DailyStuff