cant clear cache from my browser in php

萝らか妹 提交于 2019-12-24 11:53:41

问题


<?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:


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



来源:https://stackoverflow.com/questions/44261575/cant-clear-cache-from-my-browser-in-php

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