codeigniter force https

1. create /hooks/ssl.php

function force_ssl()
{
$CI =& get_instance();
$CI->config->config[‘base_url’] = str_replace(‘http://’, ‘https://’, $CI->config->config[‘base_url’]);
if ($_SERVER[‘HTTP_X_FORWARDED_PROTO’] != ‘https’) redirect($CI->uri->uri_string());
}

function force_ssl(){    $CI =& get_instance();    $CI->config->config[‘base_url’] = str_replace(‘http://’, ‘https://’, $CI->config->config[‘base_url’]);    if ($_SERVER[‘HTTP_X_FORWARDED_PROTO’] != ‘https’) redirect($CI->uri->uri_string());}

2. enable hook in /config/config.php

$config[‘enable_hooks’] = TRUE;

3. edit /config/hook.php

$hook[‘post_controller_constructor’][] = array(

‘function’ => ‘force_ssl’,

‘filename’ => ‘ssl.php’,

‘filepath’ => ‘hooks’

);

This entry was posted in ไม่มีหมวดหมู่. Bookmark the permalink.

ใส่ความเห็น