Page 1 of 1

PHP: Clear browser cache

PostPosted: Thu Feb 26, 2009 11:07 pm
by weblivehelp
Hi there,

this month, a small, simple, yet very useful function: A function to clear the user's browser cache!

So here goes the code:

Code: Select all
<?php
function clearBrowserCache() {
   header("Pragma: no-cache");
   header("Cache: no-cache");
   header("Cache-Control: no-cache, must-revalidate");
   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
}
?>


Usage (simply call the function):

Code: Select all
<?php
   clearBrowserCache();
?>


This works for most browsers (IE 5+, FF 1+, Safari 3+, Opera 8+, Chrome 1+, and many more untested should work).

You should use this function before any output (this includes blank lines) !!

Use it wisely :ugeek:

Hey

PostPosted: Thu May 14, 2009 12:38 am
by geoldidge
Just wanted to introduce myself, been a lurker on here for a while. Are there any subjects that we can't talk about on here?