dongmei1911
2014-06-12 05:29 阅读 33
已采纳

CodeIgniter中的注销问题

I have a problem in logout with CI framework. When I logout & press backspace button then it will take me to logged in page.

I need to do refresh manually after logout to destroy session.

Please help me if anybody know.

Here is Code for Logout:

function logout() {
        //pr($this->session->userdata[$this->section_name]);
        //exit;
        $lng = (isset($this->session->userdata[$this->section_name]['site_lang_code']) && $this->session->userdata[$this->section_name]['site_lang_code'] != "") ? $this->session->userdata[$this->section_name]['site_lang_code'] : 'es';

        if (isset($this->session->userdata[$this->section_name]['social_login']) && $this->session->userdata[$this->section_name]['social_login'] == 1) {
            $this->SocialLogout($this->session->userdata[$this->section_name]['socialgateway']);
        }
        $this->session->unset_userdata($this->section_name);

        redirect(site_url($lng));
        exit;
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    douzhang3822 douzhang3822 2014-06-12 05:35

    This has to be something with cache control meaning browser caching. I don't think redirect helps. you should disable this and use CodeIgniters Cache Library if any caching is needed.

    Add the following to the pages where users are required to be logged in:

    //Prevent browsers from using history to browse in the user system.
    
    $this->CI->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
    $this->CI->output->set_header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
    $this->CI->output->set_header("Pragma: no-cache"); 
    

    When pressing back in the browser the page will be refreshed.

    点赞 评论 复制链接分享
  • douhulao7642 douhulao7642 2014-06-12 05:33

    use redirect() to go to the main/home page after logout!

    $this->session->unset_userdata('login');
    redirect('mainController/index', 'refresh');
    
    点赞 评论 复制链接分享
  • douan3019 douan3019 2014-06-12 09:56
    $this->session->sess_destroy();
    redirect("controller/");
    
    点赞 评论 复制链接分享

相关推荐