Free, tested & ready to use examples : PHP Safari Internet Explorer IE Firefox disable cache caching
AnyExample.com
 
Webanyexample.com
 

Completely disable any browser caching

abstract 
Here is a simple function which sends combination of headers that completely disable any browser caching.
compatible 
  • PHP 4.0 or higher
  • PHP 5
source code: php
<?php 

function ae_nocache()
{
    
header("Expires: Tue, 03 Jul 2001 06: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");
}

?>

Usage example:

source code: php
<?php 

ae_nocache
();
// disable caching

// output some highly dynamic information
// time with microseconds
list($usec, $sec) = explode(" ", microtime());
echo
$sec.'.'.$usec;

?>
tested by AnyExample.com on 2007-05-30
  • FreeBSD 6.2 :: PHP 5.2.1
  • RHEL 5.0 :: PHP 4.4.5
  • Mac OS X :: Safari
  • Mac OS X :: Firefox 2.0
  • Windows XP :: Internet Explorer 6.0
  • Windows Vista :: Internet Explorer 7.0
 


 
© AnyExample 2007
License | Privacy | Contact