Clear cache on back press to prevent going back on login page or previous page after logout

最后都变了- 提交于 2019-12-19 11:26:08

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/13099805/clear-cache-on-back-press-to-prevent-going-back-on-login-page-or-previous-page-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!