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

Bhu
  • 27
  • 1
  • 10

1 Answers1

0

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

Hannoun Yassir
  • 20,583
  • 23
  • 77
  • 112
  • thank you for your reply can you please tell me how to remove cache still it is not removing cache from browser . – Bhu May 30 '17 at 13:11
  • browser cache . – Bhu May 30 '17 at 13:18
  • You can't clear the browser cache from the server. That could be a serious vulnerability. This previous code allows you to only tell the browser not to cache your current "page". – Hannoun Yassir May 30 '17 at 13:22