dsgo31121
2012-10-27 11:34
浏览 244
已采纳

在退出时清除缓存以防止在注销后返回登录页面或上一页

this is bugging me for a week already. Well I just badly needed to clear the cache of the login page after the user successfully logged in and prevent user from viewing the previous page after logging out when the back button is pressed. I tried adding this codes up in my work (both index page and the login page) in codeigniter but still nothing happens

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Pragma: no-cache");

as well as this one:

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="01 Jan 1970 00:00:00 GMT">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

Im already thinking about an ansynchronous task to run in background to check the session but well I'm not that good in AJAX. Well what I just wanted is to make it as simple as the ruby on rails done using Cache-Control: no-cache. By the way I also don't have the knowledge on ruby but seeing that code makes me wonder why there is no simple solution like that in codeigniter? Any solution to do the trick for this one?

图片转代码服务由CSDN问答提供 功能建议

这已经困扰了我一个星期了。 好吧,我非常需要在用户成功登录后清除登录页面的缓存,并防止用户在按下后退按钮后退出后查看上一页。 我尝试在codeigniter中添加这些代码(索引页面和登录页面),但仍然没有任何反应

  header(“Cache-Control:no-cache,must  -revalidate“); 
header(”Expires:Mon,26 Jul 1997 05:00:00 GMT“); 
header(”Pragma:no-cache“); 
   
 \  n 

以及这一个:

 &lt; META HTTP-EQUIV =“CACHE-CONTROL”CONTENT =“NO-CACHE”&gt; 
&lt; META HTTP  -EQUIV =“EXPIRES”CONTENT =“1970年1月1日00:00:00 GMT”&gt; 
&lt; META HTTP-EQUIV =“PRAGMA”CONTENT =“NO-CACHE”&gt; 
   
 
 

我已经在考虑在后台运行的同步任务来检查会话但是我在AJAX中并不是那么好。 好吧我想要的是使用 Cache-Control:no-cache 使其像使用rails上的ruby一样简单。 顺便说一下,我也没有关于ruby的知识,但看到代码让我想知道为什么在codeigniter中没有像这样的简单解决方案? 有什么解决办法来解决这个问题吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dsxpt62448 2012-10-27 11:56
    最佳回答

    What about using codeigniter output class, in your controller:

    $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
    $this->output->set_header("Pragma: no-cache");
    
    评论
    解决 无用
    打赏 举报