所以我有这个登录方法:
myImg.length
然后我使用这个简单的方法注销:
public function login(){
$this->form_validation->set_rules('username','Username','trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('password','Username','trim|required|min_length[4]|xss_clean');
if($this->form_validation->run()== FALSE) {
//Loading View
$this->load->view('admin/layouts/login');
$username = $this->input->post('username');
$password = $this->input->post('password');
//Validate Username & Password
$user_id = $this->Authenticate_model->login($username, $password);
if($user_id){
$user_data = array(
'user_id' => $user_id,
'username' => $username,
'logged_in' => true
);
//Set session userdata
$this->session->set_userdata($user_data);
} else {
//Set message
$this->session->set_flashdata('pass_login', 'You are now logged in');
redirect('admin/dashboard');
}
}
}
所以基本上我没有设置我的所有会话public function logout(){
//Unset User Data
$this->session->unset_userdata('user_id');
$this->session->unset_userdata('username');
$this->session->unset_userdata('logged_in');
$this->session->sess_destroy();
redirect('admin/authenticate/login');
}
,然后重定向回登录控制器。会发生什么,当我重定向回登录页面时,我会再次自动登录,就像我的会话数据仍然有效并存在一样。为什么会这样?
答案 0 :(得分:1)
你可以尝试
unset($this->session->userdata('user_id'));
unset($this->session->userdata('logged_in'));
unset($this->session->userdata('username'));
或者只是
$this->session->sess_destroy();
确保您的会话库已自动加载,并根据codeigniter的版本
配置了您的设置答案 1 :(得分:-2)
也许您在__construct上放置了“如果session == true,则为重定向”代码,这是我的问题:v