用session判断是否登录
CI中session判断用户是否登录放在哪个地方来方便所有的控制器判断,是用钩子么?求助本帖最后由 yuzhigang5460 于 2011-9-21 19:50 编辑
大概stblog里的方式比较经典。
class ST_Auth_Controller extends Controller {
protected function __construct() {
parent::Controller();
/** 加载验证库 */
$this->load->library('auth');
/** 检查登陆 */
if(!$this->auth->hasLogin())
{
redirect('admin/login?ref='.urlencode($this->uri->uri_string()));
}
…
}
}
Auth里有用session判断访问权限的代码,其他需登录的控制器继承于ST_Auth_Controller ;
当然你可以使用弱化的登录判断;
class SP_Controller extends CI_Controller {
protected $_profile = array();
protected $_data = array('page_title'=>'');
public function __construct()
{
parent::__construct();
$this->_pre_control();
}
protected function _pre_control()
{
$this->_profile = $this->session->userdata('profile');
if(!empty($profile))
{
$this->_data['user'] = unserialize($profile);
$this->_data['has_login'] = true;
}
else
$this->_data['has_login'] = false;
}
} 用数据库存session 可以試試看這個
https://github.com/benedmunds/CodeIgniter-Ion-Auth if(empty($_SESSION['uid'])){
跳转代码
} 顺路学习下,刚准备做个登陆的东西学习下ci 帖子好少哦 :hug::o
页:
[1]