代码点火器会话无法关闭


Codeigniter Session cannot be closed

我正在使用代码点火器开发应用程序。在此应用程序中,当用户单击注销按钮时,我取消设置会话,但是当我单击浏览器中的后退按钮时,我会看到上次注销的页面。

如何解决这个问题?

一个解决方案是使用 POST 和模式 PRG(POST-REDIRECT-GET):

创建注销按钮:

<?php echo form_open('logout');?
<button type="submit">Logout</button>
<?php echo form_close();?>

在控制器中:

public function logout{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  // destroy session
  $this->session->sess_destroy();
  // redirect to other page
  redirect('login', 'refresh');
 }
}

这解决了"后退"按钮问题,也有助于抵御CSRF攻击。

我已经有了这种事情,我所做的是这样的:

在您的访问中:

 <IfModule mod_headers.c>
 Header add Cache-Control:  "no-store, no-cache, must-revalidate"
 </IfModule>

我对你的问题是,你必须自动清除缓存,这样一旦你取消设置会话,你就无法回到上一页(我的意思是查看最后一页)。

如果您尝试在 PHP 中执行此操作,则想法相同。

/* content security */
function weblock() {
    $ci =& get_instance();
    $ci->load->library('session');
    $ci->load->model('mlogin');
    // clear cache to prevent backward access
    $ci->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
    $ci->output->set_header("Pragma: no-cache");
    // prevent unauthenticated access
    if($ci->session->userdata('user_data')==FALSE) { redirect('clogin/logout');}
    // prevent invalid authentication
    if(!$ci->mlogin->authenticate()) { redirect('clogin/logout'); }
}

尝试创建这样的函数。只需在控制器的每个构造上调用它。

希望这能启发你:)

          ##Add this Code in Constructor ##
     ## start Constructor ##
            //**********  Back button will not work, after logout  **********//
        header("cache-Control: no-store, no-cache, must-revalidate");
        header("cache-Control: post-check=0, pre-check=0", false);
        // HTTP/1.0
        header("Pragma: no-cache");
        // Date in the past
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        // always modified
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
    //**********  Back button will not work, after logout  **********//
   ## End Constructor ##
public function index(){
        redirect('home/logout');
    }
public function home() { 
               $this->form_validation->set_rules('username', 'User', 'trim|required');
               $this->form_validation->set_rules('password', 'Password', 'trim|required');
               if($this->form_validation->run() AND $data['records'] =$this->task_model->check_login()) 
                     { 
                     $this->session->set_userdata('logged_in',TRUE);
                     $this->load->view('home'); 
                    }
                    else {
                       redirect('task/logout'); 
                       }
                  }
      public function logout(){ 
          $this->session->unset_userdata('userid');
          $this->session->unset_userdata('username');
          $this->session->destroy();
          redirect(base_url());
        }

试试这个.它将解决"后退"按钮问题