如何让你的CI框架支持https协议呢,根据下面解释的操作设置一下就好了。
1、修改你的项目下 application/config/config.php 文件
(1)、将base_url 后面的链接加上 https 如图:,
将enable_hooks设置成TRUE
2、在你的项目下 application/config/hooks.php 文件中加入以下代码
$hook['post_controller_constructor'][] = array(
'function' => 'redirect_ssl',
'filename' => 'ssl.php',
'filepath' => 'hooks'
);
3、在你的项目的application/hooks下 新建 ssl.php文件,内容如下:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function redirect_ssl() {
$CI =& get_instance();
$class = $CI->router->fetch_class();
$exclude = array(); // add more controller name to exclude ssl.
if(!in_array($class,$exclude)){
// redirecting to ssl.
if ($_SERVER['SERVER_PORT'] != 443)
{
redirect($CI->config->config['base_url'].$_SERVER['REQUEST_URI']);}
}
else
{
// redirecting with no ssl.
if ($_SERVER['SERVER_PORT'] == 443)
{
redirect($CI->config->config['base_url'].$_SERVER['REQUEST_URI']);
}
}
}
?>