Error: while login and logout using codeigniter [duplicate]

青春壹個敷衍的年華 提交于 2019-12-07 01:52:36

Hope this will help you :

your logout method should be like this :

public function logout()
{
    $this->session->sess_destroy();
    redirect('Home/login');
} 

Your Backend should be like this : you have to check it in all controllers

public function Backend()
{ 
   if (! $this->session->userdata('is_logged_in')) redirect('Home/login'); 
   $this->load->view('backend'); 
} 

For more : https://www.codeigniter.com/user_guide/libraries/sessions.html#destroying-a-session

unset_userdata() can be used to remove it, by passing the session key.

so, logout function will be change like this.

public function logout()
{
    $this->session->unset_userdata('username');
    $this->session->unset_userdata('password');
    $this->session->unset_userdata('is_logged_in');

/*
Or

    $array_items = array('username' , 'password' , 'is_logged_in');
    $this->session->unset_userdata($array_items);
*/

    $this->session->sess_destroy();
    redirect('Home/login');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!