简体   繁体   English

注销后的CodeIgniter后退按钮

[英]CodeIgniter back button after logout

I'm trying to stop/disable the back button functionality of the browser when a user logs out of my CodeIgniter (PHP) app. 当用户退出我的CodeIgniter(PHP)应用程序时,我正在尝试停止/禁用浏览器的后退按钮功能。 But, I think the browser is caching the page so it becomes visible despite the session being destroyed from logout. 但是,我认为浏览器正在缓存页面,因此尽管会话从注销中被销毁,它仍然可见。

I know the session is dead because when the user tries to do anything (click any link etc) they are kicked out through the methods in my controller. 我知道会话已经死了,因为当用户尝试做任何事情(点击任何链接等)时,他们会通过控制器中的方法被踢出。

It's not ideal to have the back button working in this manner since the previous page contains confidential information. 由于上一页包含机密信息,因此后退按钮以这种方式工作并不理想。

Not a clue how to tackle this one, maybe a redirect page in between (but then the user could slam the back button really quick right?), help! 不知道如何解决这个问题,也许是介于两者之间的重定向页面(但是用户可以快速砰地关上后退按钮吗?),帮助!

Thanks. 谢谢。

I think this could help you out, it works for me. 我认为这可以帮助你,它对我有用。

CodeIgniter Framework version: 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 version: 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');

if you are using PHP OOP put the above code in your constructor to initialize on your pages. 如果您使用的是PHP OOP,请将上述代码放在构造函数中以在您的页面上进行初始化。

Add this to prevent caching of the previous page: 添加此项以防止缓存上一页:

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

My solution for this problem: 我解决这个问题的方法:

  1. Check that the cookie is set will with an if. 检查cookie是否设置为if。
  2. Step parameters and call the login method of user model. 步骤参数并调用用户模型的登录方法。
  3. Finally charge the corresponding views. 最后收取相应的意见。

If the cookie is not set will redirected to the login page. 如果未设置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'); 
}

I hope you learn! 我希望你学习! And sorry for my english! 抱歉我的英语! :-) :-)

注销后转到一页显示一些消息,如“很快见到你”,并在一段时间后重定向到所需的页面,这可能会解决您的问题,如下面的代码重定向第二次标题(“刷新3;网址= home.php” );

You could use javascript to close the window after they logout - thus removing any ability to go back pages. 您可以在注销后使用javascript关闭窗口 - 从而删除任何返回页面的功能。

Alot of online banks do this to solve this exact issue. 很多在线银行都这样做来解决这个问题。

I think the following should help you out 我认为以下内容可以帮到你

1) Create a logout.php file and add the following code to it 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) Modify your logout function to load a above view file logout.php 2)修改您的注销功能以加载上面的视图文件logout.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM