开发者

How to Clear Cache using PHP

开发者 https://www.devze.com 2023-04-11 08:21 出处:网络
i am trying to clear browser Cache using PHP here is my code header(\"Cache-Control: no-cache, must-reval开发者_JAVA技巧idate\");

i am trying to clear browser Cache using PHP

here is my code

header("Cache-Control: no-cache, must-reval开发者_JAVA技巧idate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-Type: application/xml; charset=utf-8");

this code in not working can anybody have idea .

thanks in advance


You can't clear the cache from the server side, only instruct the browser not to do any more caching.

The headers you have used will work - they will tell the browser not to cache the content you just sent. However, if the browser already has a cached version of the page, it won't send a request, and will not get the headers you are setting, so it won't know to abandon the cached version.

Press CTRL+F5 to force the browser to refresh the content. After you do this, you should get the expected behaviour.


You cannot clear the local browser cache using PHP. You can only clear sessions/cookies that the user has on the website running the PHP script.


We use this in production to prevent users from being able to view authenticated pages after they have logged out by pressing back on their browser (it lives in AppController::beforeFilter()):

// disable local browser cache for authenticated pages (so user can't press back after logging out)
if ($this->Auth->user()) {
    $this->header("Cache-Control: no-cache, no-store, must-revalidate"); // 'no-store' is the key
    $this->header("Expires: Mon, 1 Jan 2001 00:00:00 GMT"); // date in the past
}


Please add this code to your php page

<?php
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消