How can I have CodeIgniter load specific pages using SSL? I have an apache2/mode_ssl
server. mod_ssl
uses a different document root than non-secure
I would maintain two sets of the code and handle a forced redirect to HTTPS pages with a post_controller_constructor hook. The hook will be called before each page is rendered to check if the visitor should be redirected to HTTPS based on their current location on your site.
STEP 1
Create file: system/application/hooks/SecureAccount.php
obj =& get_instance();
}
//--------------------------------------------------
//Redirect to https if in the account area without it
function index()
{
if(empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] !== 'on')
{
$this->obj =& get_instance();
$this->obj->load->helper(array('url', 'http'));
$current = current_url();
$current = parse_url($current);
if((stripos($current['path'], "/account/") !== false))
{
$current['scheme'] = 'https';
redirect(http_build_url('', $current), 'refresh');
}
}
}
}
?>
STEP 2
Customize the path in the function for which areas of your site should be forced to use HTTPS.
STEP 3
Add the following to system/application/config/hooks.php
/* Force HTTPS for account area */
$hook['post_controller_constructor'] = array(
'class' => 'SecureAccount',
'function' => 'index',
'filename' => 'SecureAccount.php',
'filepath' => 'hooks',
'params' => array()
);