Problem Description: Using XML HTTP Request, Internet Explorer caches response sent back from the server script.
Solution: You have to send several headers along with response to the browser to prevent caching.
Script has been tested in IE/Firefox and works fine...
<?
//PHP Requests Handler
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache");
//header ("Content-type: application/xml"); //uncomment this line if you plan to send XML
//...................
echo "you should see now random numbers in your browser:".rand().", timestamp: ".time();
?>
You may have script on the server, that takes time to execute, like displaying sitemaps or customer database.
So, you don't want to call the script again and again, but just tell the browser to get results from the cache.
All you have to do, is to skip execution of the script on the server and send empty response with the headers below!
<?
//PHP Requests Handler
header("Expires: Mon, 26 Jul 3000 05:00:00 GMT"); // Date in the future
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: cache");
header("Pragma: cache");
//header ("Content-type: application/xml"); //uncomment this line if you plan to send XML
//...................
echo "you should always see the same result in your browser:".rand().", timestamp: ".time();
?>
Comments