Skip to content

Instantly share code, notes, and snippets.

@grimzy
Last active November 19, 2018 22:35
Show Gist options
  • Save grimzy/c47bedd37ebfcbe197814ec3689775df to your computer and use it in GitHub Desktop.
Save grimzy/c47bedd37ebfcbe197814ec3689775df to your computer and use it in GitHub Desktop.
CI Dynamic base_url
$config['base_url'] = (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http') . "://" . (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost/') . str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
// OR
$server_port = (isset($_SERVER['SERVER_PORT']) && !empty($_SERVER['SERVER_PORT'])) ? $_SERVER['SERVER_PORT'] : 80;
$server_name = (isset($_SERVER['SERVER_NAME']) && !empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost/';
$script_name = str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);
$config['base_url'] = ($server_port == 443 ? 'https' : 'http') . "://" . $server_name . $script_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment