[英]How can I avoid being logged in again when clicking back button of browser in codeigniter?
在codeigniter中单击浏览器的后退按钮时,如何避免再次登录? 我在注销时销毁会话,但是当我在浏览器中返回时,它仍然进入管理页面,单击浏览器的后退按钮时,它应该留在重定向页面中而不返回管理页面。 这是我在模型和控制器中的代码:
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');
}
?>
尝试将其添加到标题页-
<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");
对于相同的问题,以上对我来说很好用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.