How to disable cache on logout in CakePHP

三世轮回 提交于 2019-12-13 01:16:24

问题


I am using cakephp 2.3 version. I need to disable cache only when the user logs out. This is to prevent login in case the back button is pressed.

But for all other scenarios I don't want to disturb caching mechanism.

Right now i use the following function in AppController:

public function beforeRender() {
    $this->response->disableCache();
}

But I doubt that it disables the caching process completely. Please help!


回答1:


I don't believe the user is automatically logged back into your site if they click on the back button after logging out. I'm guessing by your question that when the user does press the back button after logging out, you want them to be forwarded to the login page. Unfortunately, the browser may cache the last page it was on and give the user the illusion that they're still logged in. Rest assured that when they try and do something that requires them to be logged in, the session ID stored in the cookie, won't be recognized and they will be forwarded to the authentication page.

One possible work around is to redirect the user to another controller action after the logout has taken place - this will introduce and additional transition in the browsers history. I don't know what will happen if they click back twice though.




回答2:


Add this to the header page of your application:

<?php
  header("Cache-Control: no-cache, no-store, must-revalidate"); 
  header("Pragma: no-cache");
  header("Expires: 0");
?>


来源:https://stackoverflow.com/questions/16457261/how-to-disable-cache-on-logout-in-cakephp

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