在codeigniter中注销

Hac*_*ker 5 php session codeigniter logout

我正在尝试在codeigniter框架中设计登录/注销页面.我的问题是,当我退出网页时,我被重定向到登录页面.当我回去时,我得到一个页面,上面写着:

文件已过期

This document is no longer available.
Run Code Online (Sandbox Code Playgroud)

但是,当我刷新此页面时,我再次登录系统(oO)

以下代码包含我的构造函数和注销功能.请帮我设计一个完美的登录注销页面

function __construct()
{
    parent::__construct(); 

    $this->load->model('user_model');    

    $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
        $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
        $this->output->set_header('Pragma: no-cache');
        $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    
}

function logout()
{
    $newdata = array(
                'user_name'  =>'',
                'user_email' => '',
                'logged_in' => FALSE,
               );

     $this->session->unset_userdata($newdata);
     $this->session->sess_destroy();

     redirect('default_controller','refresh');
}
Run Code Online (Sandbox Code Playgroud)

我尝试找到适当的注销方法,但我无法做到.

小智 16

试着像这样简单

function logout()
{
    $user_data = $this->session->all_userdata();
        foreach ($user_data as $key => $value) {
            if ($key != 'session_id' && $key != 'ip_address' && $key != 'user_agent' && $key != 'last_activity') {
                $this->session->unset_userdata($key);
            }
        }
    $this->session->sess_destroy();
    redirect('default_controller');
}
Run Code Online (Sandbox Code Playgroud)