CodeIgniter登出后返回按钮的问题

7
我正在尝试停用CodeIgniter(PHP)应用程序中用户注销时浏览器的返回按钮功能。但是,我认为浏览器正在缓存页面,因此尽管会话已从注销中销毁,页面仍然可见。
我知道会话已关闭,因为当用户尝试执行任何操作(单击任何链接等)时,他们会通过控制器中的方法被踢出。
在这种情况下,使后退按钮工作并不理想,因为上一页包含机密信息。
我不知道如何解决这个问题,也许需要在中间添加一个重定向页面(但是用户可以非常快地按下后退按钮),求助!
谢谢。

请访问以下链接:http://stackoverflow.com/questions/5251110/back-button-takes-the-user-back-to-protected-page-after-logout-zend-framework虽然不是CodeIgniter,但我认为您可以使其正常工作。 - Aurimas Ličkus
1
检查这个,我认为它会对你有所帮助:https://dev59.com/lVPTa4cB1Zd3GeqPhDbz - Ula
6个回答

14

我认为这可能对你有所帮助,它对我有效。

CodeIgniter框架版本:

$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');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0',false);
$this->output->set_header('Pragma: no-cache');

PHP版本:

header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0',false);
header('Pragma: no-cache');

如果你正在使用PHP面向对象编程,把上述代码放在你的构造函数里,以便在页面上进行初始化。


我应该把这段代码放在哪里?在控制器中还是每个视图页面中?我正在使用CodeIgniter框架。 - J Ramesh Fernandez

12

添加此代码以避免缓存上一页:

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");

1

这个问题的解决方案:

  1. 使用if语句检查cookie是否设置。
  2. 设置参数并调用用户模型的登录方法。
  3. 最后加载相应的视图。

如果cookie没有设置,将重定向到登录页面。

if(isset($_COOKIE['ci_session'])){ 
  $user= $this->security->xss_clean($this->input->post('user'));
  $pass= $this->security->xss_clean($this->input->post('pass'));

  $result = $usrLog->loguearUsuario($user, $pass);

  if($result == TRUE){
     $data = $this->session->set_userdata('logged_in', $sessArray);
     $this->load->view('pages/admin', $data);
  }

}else{
   header('Location: login'); 
}

我希望你学到了!对我的英语表示抱歉!:-)


0

登出后前往一个页面显示一些消息,如“再见”,并在一段时间后从该页面重定向到所需的页面,这可能会解决您的问题 ,如下代码第二次重定向时 header("Refresh 3; url=home.php");


http://stackoverflow.com/questions/6648093/php-prevent-going-back-page-after-log-out - user1370510

0
你可以使用JavaScript在用户注销后关闭窗口,从而消除任何返回页面的能力。 很多在线银行都这样做来解决这个确切的问题。

0
我认为以下内容应该能帮到你:
1)创建一个logout.php文件,并添加以下代码:
<html>
 <head>
  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$( "#submit" ).trigger( "click" );
});
</script>
</head>

<body>
<form action="<?php echo base_url();?>login" method="post">
<input type="submit" id="submit" style="display: none;">
</form>
</body>
</html>

2) 修改您的注销函数,加载一个名为logout.php的视图文件


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接