Logout in codeigniter

48,282

Solution 1

try to be simply like this

function logout()
{
    $user_data = $this->session->all_userdata();
        foreach ($user_data as $key => $value) {
            if ($key != 'session_id' && $key != 'ip_address' && $key != 'user_agent' && $key != 'last_activity') {
                $this->session->unset_userdata($key);
            }
        }
    $this->session->sess_destroy();
    redirect('default_controller');
}

Solution 2

don't need to use this line

$this->session->sess_destroy();

Share:
48,282
Hacker Rocker
Author by

Hacker Rocker

Updated on July 09, 2022

Comments

  • Hacker Rocker
    Hacker Rocker almost 2 years

    I am trying to design a login/logout page in codeigniter framework.My problem is that when I logout of the web-page I am getting redirected to a login page. When I go back I am getting a page which says:

    Document Expired

    This document is no longer available.
    

    But when I refresh this page I am getting logged into the system again (o.O)

    The following codes contain my constructor and logout functionalities. Please help me to design a perfect login logout page

    function __construct()
    {
        parent::__construct(); 
    
        $this->load->model('user_model');    
    
        $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
            $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
            $this->output->set_header('Pragma: no-cache');
            $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    
    }
    
    function logout()
    {
        $newdata = array(
                    'user_name'  =>'',
                    'user_email' => '',
                    'logged_in' => FALSE,
                   );
    
         $this->session->unset_userdata($newdata);
         $this->session->sess_destroy();
    
         redirect('default_controller','refresh');
    }
    

    I tried find proper logout method but I am not able to.

  • Hacker Rocker
    Hacker Rocker over 10 years
    I didnt get u .. i am still facing problem with mylogout