cant clear cache from my browser in php

2019-07-26 06:01发布

<?php
$_SESSION['test']="demo";
echo $_SESSION['test'];
function clearBrowserCache() {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  
header ("Cache-Control: no-cache, must-revalidate");  
header ("Pragma: no-cache");
}
clearBrowserCache();
?>

i want to make one php file which can clear cache browser. is that something wrong in my code please help me :)

1条回答
神经病院院长
2楼-- · 2019-07-26 06:37

You should not echo anything before sending headers.

<?php
function clearBrowserCache() {
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  
    header ("Cache-Control: no-cache, must-revalidate");  
    header ("Pragma: no-cache");
}
clearBrowserCache();

$_SESSION['test']="demo";
echo $_SESSION['test'];
?>

Otherwise, enable output_buffering in the php.ini

查看更多
登录 后发表回答