====== CodeIgniter SSL URLs ======
__//This is a page about an unmaintained project, and as such may contain inaccuracies and incorrect relative date references.//__
//**This method has only been tested on CodeIgniter 1.5.x. As of 2009/05/01, the current version is 1.7.1, and therefore this probably doesn't work any more.**//
For a while I have been wanting a nice way to choose between generating HTTP or HTTPS URLs with [[http://www.codeigniter.com/|CodeIgniter]] while changing code in as few places as possible.
This particular solution involves adding 5 extra configuration options:
// HTTPS base URL
$config['https_base_url'] = "https://mysite.com/";
// Prefixes for forcing ssl/nossl/auto on urls
$config['https_ssl_trigger'] = "ssl:"; // Always use https
$config['https_nossl_trigger'] = "nossl:"; // Always use http
$config['https_auto_trigger'] = "auto:"; // Use whatever was used in the current request
// Default mode
$config['https_default_trigger'] = $config['https_nossl_trigger'];
Hopefully this should make it useful yet completely configurable so that it can be used anywhere. The other part of the solution is the extending of ''CI_Config'' to overload the ''site_url()'' method with my own version that handles these "triggers". Any function that uses ''site_url()'' on a URL can now use URIs in the form '''', where the trigger is optional---this means this functionality is extended to most of the URL, Form and other miscellaneous helper functions.
If you want to be able to use ''base_url()'' to get the SSL URL (or automatically choose which one) replace the ''base_url()'' function in ''url_helper.php'' (usually at ''system/helpers/url_helper.php'') with the following:
config->item('https_default_trigger') )
{
case $CI->config->item('https_nossl_trigger'):
return $CI->config->slash_item('base_url');
case $CI->config->item('https_ssl_trigger'):
return $CI->config->slash_item('https_base_url');
default:
return $CI->config->ssl ? $CI->config->slash_item('https_base_url') : $CI->config->slash_item('base_url');
}
case 'nossl':
return $CI->config->slash_item('base_url');
case 'ssl':
return $CI->config->slash_item('https_base_url');
default:
return $CI->config->ssl ? $CI->config->slash_item('https_base_url') : $CI->config->slash_item('base_url');
}
}
?>
===== Install =====
The following file needs to be put in your /libraries/ directory:
[[http://svn.codescape.net/svn/codescape/trunk/system/application/libraries/MY_Config.php|system/application/libraries/MY_Config.php]]
Also, you will need to add the above options to your ''/config/config.php''.