在codeigniter中单击浏览器的后退按钮时,如何避免再次登录?我在注销时销毁de会话,但是当我在浏览器中回来时它仍然进入管理页面,当点击浏览器的后退按钮它应该保留在重定向的页面而不是回到管理页面。这是我在模型和控制器中的代码:
auth_model:
class Auth_model extends CI_Model {
public function login($name, $password){
$password = sha1($password);
$this->db->where('username',$name);
$this->db->where('password',$password);
$query = $this->db->get('auth');
if($query->num_rows()==1){
foreach ($query->result() as $row){
$data = array(
'username'=> $row->username,
'logged_in'=>TRUE
);
}
$this->session->set_userdata($data);
return TRUE;
}
else{
return FALSE;
}
}
public function isLoggedIn(){
header("cache-Control: no-store, no-cache, must-revalidate");
header("cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
$is_logged_in = $this->session->userdata('logged_in');
if(!isset($is_logged_in) || $is_logged_in!==TRUE)
{
redirect('/');
exit;
}
}
auth controller:
public function logout(){
$this->session->sess_destroy();
redirect('/' ,'refresh');
exit;
}
user controller
<?php
class User extends CI_Controller {
function __construct()
{
parent::__construct();
$this->template->set_layout('adminLayout.php');
$this->load->model("User_model");
$this->load->Model('Auth_model');
}
function index()
{
$this->Auth_model->isLoggedIn();
$this->template->title('Admin ::');
$this->template->build('admin/index');
}
function user()
{
$this->Auth_model->isLoggedIn();
$this->template->title('user');
$this->template->build('admin/user');
}
?>
答案 0 :(得分:0)
尝试将此添加到标题页 -
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE, NO-STORE, must-revalidate">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT=0>
header("Cache-Control: no-store, no-cache, must-revalidate");
对于同样的问题,上述内容对我来说很好。