Codeigniter,单击后退按钮浏览器时重定向到上一页

I want to be when the back button on the browser is clicked. system will redirect to previous page or to a specific page.

I've made a function to check the login session like this

public function cekAuth(){
        /* Mengecek login session
         */
        $sesi = $this->ci->session->userdata('isLogin_'.project);
        $key = $this->ci->uri->segment('1');

        if ($sesi == TRUE && $key == "access") {
            redirect('dashboard/home'); 
            exit();
        } else if($sesi == FALSE) {
            redirect('access');
            exit();
        }

    }

if the login session is TRUE and the user accesses the login page will be redirected to the dashboard. This has been successfully.

but when I logout always redirected to the dashboard and not to the login page.

LOGOUT:

function logout(){
        $this->session->sess_destroy(); 
        $this->session->set_userdata('isLogin_'.project , FALSE);
        redirect('access');
    }

Can you help me? :)

It would be great first please check your condition is perfect or not, May be if you will do on this ways get idea where is problem.

public function cekAuth(){
    /* Mengecek login session
     */
    $sesi = $this->ci->session->userdata('isLogin_'.project);
    $key = $this->ci->uri->segment('1');

    if ($sesi == TRUE && $key == "access") {
        echo '1';
        exit();
        redirect('dashboard/home'); 
    } else if($sesi == FALSE) {
        echo '2';
        exit();
        redirect('access');
    }

}

Change this line in logout function:

$this->session->set_userdata('isLogin_'.project , FALSE);  

To

$this->session->unset_userdata('isLogin_'.project , FALSE);