user2991258
user2991258

Reputation: 129

Redirect to webpage by click on back button after logout

In the below codeigniter code after i logout i can able to view page but i want not to view page after logout . I placed the controller below.

function logout()
    {
        $this->session->sess_destroy();

        $this->index();
    }

Upvotes: 1

Views: 872

Answers (5)

praveen
praveen

Reputation: 286

Hopefully you're using templates for your views and this will be painless but make sure this is in the head of each page you don't want accessible by the back button.

header("Cache-Control: no-store, no-cache, must-revalidate");
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE, NO-STORE, must-revalidate">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT=0>

Just to explain what is happening. The page is loading from your browser cache meaning the browser thinks your user is still logged in. The above lines make the browser revalidate the page on every load and won't load it from it's own cache.

Upvotes: 0

Mahmood Rehman
Mahmood Rehman

Reputation: 4331

If you are attempting to restrict user from certain page with authentication you can implement some code like this :

if($this->user->logged() == FALSE)
        { 
            redirect('login');
        }

Write down this code in your method otherwise you can write this in constructor.As for as i got from your question not from the title of your question.

Upvotes: 0

praveen
praveen

Reputation: 286

Try this

function logout()
{
$this->session->sess_destroy();       
    $this->load->helper('url');
           redirect('base_url() ,'refresh');
           exit;
}

Upvotes: 0

pratim_b
pratim_b

Reputation: 1210

Check in each controller method which loads the page whether the person is logged in or not. If not redirect. you have to do it in each function that loads a view.

Upvotes: 0

Siraj Khan
Siraj Khan

Reputation: 2348

You can try this

function logout(){

         $this->CI =& get_instance();   
         $this->CI->session->sess_destroy();
         redirect(base_url());
}

Upvotes: 3

Related Questions