【问题标题】:CodeIgniter back button after logout注销后的 CodeIgniter 后退按钮
【发布时间】:2012-05-12 05:38:44
【问题描述】:

当用户退出我的 CodeIgniter (PHP) 应用程序时,我正在尝试停止/禁用浏览器的后退按钮功能。但是,我认为浏览器正在缓存页面,因此尽管会话从注销中被破坏,它仍然可见。

我知道会话已死,因为当用户尝试执行任何操作(单击任何链接等)时,他们会通过我控制器中的方法被踢出。

后退按钮以这种方式工作并不理想,因为前一页包含机密信息。

不知道如何解决这个问题,可能是介于两者之间的重定向页面(但是用户可以非常快地按下后退按钮吗?),帮助!

谢谢。

【问题讨论】:

标签: php html codeigniter session caching


【解决方案1】:

我认为这可以帮助你,它对我有用。

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 OOP,请将上述代码放入您的构造函数中以在您的页面上进行初始化。

【讨论】:

  • 我应该在哪里添加上面的代码?在控制器或每个视图页面中?我正在使用 codeigniter 框架。
【解决方案2】:

添加此项以防止缓存上一页:

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

【讨论】:

    【解决方案3】:

    我对这个问题的解决方案:

    1. 检查 cookie 是否使用 if 设置。
    2. 单步参数,调用用户模型的登录方法。
    3. 最后给对应的view收费。

    如果没有设置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'); 
    }
    

    希望你学习!对不起我的英语! :-)

    【讨论】:

      【解决方案4】:

      注销后转到一个页面显示一些消息,例如“很快见”,然后从该页面重定向到所需页面,这可能会解决您的问题 像下面第二次重定向的代码 header("刷新 3; url=home.php");

      【解决方案5】:

      您可以在他们注销后使用 javascript 关闭窗口 - 从而消除任何返回页面的能力。

      很多网上银行都这样做是为了解决这个确切的问题。

      【讨论】:

        【解决方案6】:

        我认为以下内容应该对您有所帮助

        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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-01-18
          • 2011-08-05
          • 2023-03-29
          • 2015-07-11
          • 2013-09-21
          • 1970-01-01
          • 2011-03-26
          • 2018-08-03
          相关资源
          最近更新 更多