http://codeigniter.org.cn/forums/thread-10877-1-1.htmlphp
一直没找到CI的权限认证扩展,之前好像找到过一个老外的扩展,不过不怎么好用,如今记不清了,后来仿着jsp firter的方式用CI钩子写了一下,感受还能够,作个小网站,小应用足够了,不必搞得太复杂。看到不少人在网上问,这里把咱们的方法分享一下,若是你有更好的实现,也请记得分享给咱们。^_^
html
$config['enable_hooks'] = TRUE;数据库
$hook['post_controller_constructor'] = array( 'class' => 'ManageAuth', 'function' => 'auth', 'filename' =>'ManageAuth.php', 'filepath' => 'hooks');编程
/** 后台权限拦截钩子 * @link http://www.php-chongqing.com * @author bing.peng * */
class ManageAuth {
private $CI;
public function __construct()
{
$this->CI = &get_instance();
}
//权限认证
public function auth()
{
$this->CI->load->helper('url');
if ( preg_match("/manage.*/i", uri_string()) ) {
// 须要进行权限检查的URL
$this->CI->load->library('session');
if( !$this->CI->session->userdata('username') ) {
// 用户未登录
redirect('login');
return;
}
}
}
}