1

I make a link for logout in my view page.When I clicked it goes to another page but when I click the back button of browser it comes back to last page I log outed from it.what should I do to prevent this action?
cotroller:

function logout(){
$this->session->sess_destroy();
redirect('acontrol/index');}

thanks for your help.

setara
  • 31
  • 8

2 Answers2

0

You can check before the function calls that whether a session is there are not.If the session is empty then you need to redirect to login page again.Better you can check at __construct function in your class.It will called prior to your function call so,for each page the page will be redirect to login whenever your session is empty.

function __construct() {
   if($this->session->userdata('iUserId') == '') {
       // Redirect to Login page
       redirect('controllername/login');
   } 
}
GautamD31
  • 28,552
  • 10
  • 64
  • 85
0

you can check the session into controller construct method

public function __construct()
    {
        // Initialization of class
        parent::__construct();

        if(!$this->session->userdata('id')){

            $this->session->set_flashdata('error', 'Please login first');

            /* if user is not login then
            redirect back to login page and show error
            */

            redirect('admin/login/index');
        } 

    }
Dexter
  • 1,804
  • 4
  • 24
  • 53