0
所以我有這樣的登錄方法:
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');
}
所以基本上我我解封所有會話userdata
然後重新導向到登錄控制器。然後會發生的是,當我重定向回登錄頁面時,我會自動重新登錄,就像我的會話數據仍然有效並存在一樣。爲什麼會發生?
您同時使用未設置並配置了您的設置$這 - >會話級> sess_destroy();嘗試一個或其他? – user4419336
是的,我刪除了'''sess_destroy()'''它工作,但理論上它應該與它一起工作。奇怪。 – Tachi
其實我錯了。它不工作... – Tachi