Codeigniter pressing logout button and disable the back browser button

前端 未结 4 1263
猫巷女王i
猫巷女王i 2020-12-20 04:03

Hello guys i am using CodeIgniter Framework, i have a problem within after logout, the session is already destroyed and redirect to login form, and after redirecting to logi

4条回答
  •  天涯浪人
    2020-12-20 04:14

    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

提交回复
热议问题