php ci框架 hook,ci框架hook钩子

[php]代码库//启动hooks

//app/config/config.php

$config['enable_hooks'] = TRUE;

//hooks配置

///app/config/hooks.php

$hook['post_controller_constructor'][] = array(

'function' => 'check_ssl',

'filename' => 'ssl.php',

'filepath' => 'hooks',

);

//插件编写

//app/hooks/ssl.php

function check_ssl(){

$CI =& get_instance();

$class = $CI->router->fetch_class();

$method = $CI->router->fetch_method();

$ssl = $CI->config->item('ssl_class_method');

$partial = $CI->config->item('no_ssl_class_method');

if(in_array($class.'/'.$method,$ssl)){

//force_ssl();

$CI =&get_instance();

$CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']);

if ($_SERVER['SERVER_PORT'] != 443) redirect($CI->uri->uri_string());

}

else if(in_array($class.'/'.$method,$partial))

{

return;

}

else{

//unforce_ssl

$CI =&get_instance();

$CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']);

if ($_SERVER['SERVER_PORT'] == 443) redirect($CI->uri->uri_string());

}

}

//config 配置需要使用https的 class method

//app/config/config.php

$config['ssl_class_method'] = array(

'U_class/A_method',

'V_class/B_method',

'W_class/C_method',

'X_class/D_method',

); //强制使用ssl

$config['no_ssl_class_method'] = array(); //强制不使用ssl

694748ed64b9390909c0d88230893790.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值