Codeigniter pressing logout button and disable the back browser button Codeigniter pressing logout button and disable the back browser button codeigniter codeigniter

Codeigniter pressing logout button and disable the back browser button


I tired to implement this option but it doesn't works well. So i implement new logic on this.

Simply check is session is set in every main methods. Below code help you

In logout(define in controller)

function __construct(){    parent::__construct();    ob_start(); # add this}public function logout(){    $this->load->driver('cache');    $this->session->sess_destroy();    $this->cache->clean();    ob_clean();    redirect('home'); # Login form or some other page         }

In dashboard(Function)

public function home(){    $logged_in = $this->session->userdata('logged_in');    if($logged_in != TRUE || empty($logged_in))    {        #user not logged in        $this->session->set_flashdata('error', 'Session has Expired');        redirect('user_logging'); # Login view    }    else    {        #user Logged in        $this->load->view("viewname",$data);    }}

In Login(function)

$session = array(    'username'  => $name,    'logged_in' => TRUE);$this->session->set_userdata($session);


You are trying to solve the wrong problem: If going back after logout leads to a page full of errors, going to that page directly would cause the same problem.

This should never occur, instead when someone tries to open a page that should not be opened when not logged-in, the visitor should be directed to the login page.

Apart from that you should not mess with the user's browser experience. So even you could, you should not disable the back-button. And even if you could, it could probably easily be circumvented by disabling javascript (for example...).


first of all, set the userdata session value when you successfully log in to the admin panel use this line after all the validation you have done on login from

$this->session->set_userdata('admin_id',$admin_id);

you can just do 1 thing to avoid direct login of ant of the pages of your user panel or admin panel, just make a constructor in your admin controller like this

public function __construct(){    parent::__construct();    if(! $this->session->userdata('admin_id')){        return redirect('login_controller');//your login controller which have login page as view in index function//    }} 

and use the logout function like this:

public function logout(){    $this->session->unset_userdata('admin_id');    return redirect('login_controller');}

by this way, after you log out from the admin panel and try to use back button or try to use the direct calling of any of the admin panel page or function it won't open,it works for me and still using this code in user and admin panel making