【问题标题】:View the Dashboard after logout with browser back button使用浏览器后退按钮注销后查看仪表板
【发布时间】:2018-08-14 10:19:18
【问题描述】:

我是 codeigniter 框架的新手。我知道这个问题已经被问过很多次了。我已经进行了研发,但我无法让它发挥作用。我现在卡住了。我正在使用 codeigniter 框架 2.2.2。我使用会话登录如下:

登录控制器

public function loginMe()
{
    $this->load->library('form_validation');

    $this->form_validation->set_rules('username', 'Username', 'required');
    $this->form_validation->set_rules('password', 'Password', 'required|max_length[32]|');

    if($this->form_validation->run() == FALSE)
    {
        $this->index();
    }
    else
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');

        $result = $this->login_model->loginMe($username, $password);

        if(count($result) > 0)
        {
            foreach ($result as $res)
            {
                $sessionArray = array('userId'=>$res->userId,
                                        'role'=>$res->roleId,
                                        'roleText'=>$res->role,
                                        'name'=>$res->name,
                                        'isLoggedIn' => TRUE
                                );

                $this->session->set_userdata($sessionArray);

                redirect('/dashboard');
            }
        }
        else
        {
            $this->session->set_flashdata('error', 'Username or password mismatch');

            redirect('/login');
        }
    }
}

当用户注销时,我在用户控制器中调用注销函数:

用户控制器注销功能:

function logout() {

    $this->session->sess_destroy ();
     ob_clean();
    redirect ('login');
}

到目前为止,一切正常。我可以注销登录页面,但是当我单击浏览器后退按钮时,我可以看到仪表板。不应该这样做。 我的用户控制器构造函数正在检查会话或 isloggedin()。

public function __construct()
{
    parent::__construct();
    ob_start();
    $this->load->model('user_model');

    $this->isLoggedIn();   
}
function isLoggedIn() {
    $isLoggedIn = $this->session->userdata ( 'isLoggedIn' );

if (! isset ( $isLoggedIn ) || $isLoggedIn != TRUE || empty($isLoggedIn)) {
    $this->session->set_flashdata('error', 'Session has Expired');
        redirect ( 'login' );
    } else {
        $this->role = $this->session->userdata ( 'role' );
        $this->vendorId = $this->session->userdata ( 'userId' );
        $this->name = $this->session->userdata ( 'name' );
        $this->roleText = $this->session->userdata ( 'roleText' );
        $this->lastLogin = $this->session->userdata ( 'lastLogin' );

        $this->global ['name'] = $this->name;
        $this->global ['role'] = $this->role;
        $this->global ['role_text'] = $this->roleText;
        $this->global ['last_login'] = $this->lastLogin;
    }
}

我已尽我所能,但它不起作用。我关注了这个Codeigniter pressing logout button and disable the back browser button。但它不能解决我的问题。在这方面的任何帮助将不胜感激。提前致谢。

【问题讨论】:

  • CI 2 的会话一团糟,有什么理由不能升级?
  • @Alex 我正在使用某人的模板。所以我想坚持下去。感谢您的建议。

标签: php codeigniter login logout


【解决方案1】:

您可以对一个函数进行清除缓存并在构造函数中调用它。

function clear_cache()
{
   $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
   $this->output->set_header("Pragma: no-cache");
}

【讨论】:

    【解决方案2】:

    你必须把缓存控制头,像这样:

    $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
    $this->output->set_header("Pragma: no-cache");
    

    【讨论】:

    • 我以前也这样做过,但它不起作用,因为我不知道准确的放在哪里。感谢您的评论@EugeneR
    猜你喜欢
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 2017-01-18
    • 2022-01-09
    • 2015-04-21
    • 1970-01-01
    • 2013-07-20
    • 2022-01-21
    相关资源
    最近更新 更多