Search code examples
androidbrowserwebkitback-buttoncache-control

Prevent page caching not working on Android Webkit browser


I'm having troubles with a script which sends HTTP headers to prevent page caching on Android Webkit browsers.Script works fine on popular browser like Chrome, FF and IE but not Android Webkit Browser. I've tested it on 2.1 and 2.2 Androids and page is always cached. When I hit back button page is not reloaded.

Here is my sample script:

<?php

session_start();
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-store, no-cache, must-revalidate");  
header("Cache-Control: post-check=0, pre-check=0", false); 
header("Pragma: no-cache");  

if ($_SESSION['var'] == 1)
$_SESSION['var'] = 0;
else $_SESSION['var'] = 1;

?>
<html>
   <body>
     <a href="http://www.w3schools.com">Go away from current page</a> 
     <p>Value is <?php echo $_SESSION['var']?> .</p>
   </body>
</html>

Solution

  • Solution to this issue with Webkit Browsers is mentioned in the post Why doesn't Safari honor my cache-control directive?