Clear Browser Cache Using HTML or PHP

To clear the browser cached page or to force the browser to re-download the content of a page, you can place the following HTML code in the header tags (<head>) of the page. This code will ask the broswer to ignore any saved copies of the page, and to re-download page content.

HTML Code:





 

If you prefer working with PHP, you can do the exact same using this PHP code:

PHP Code:

header ("Expires: ".gmdate("D, d M Y H:i:s", time())." GMT");  
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  
header ("Cache-Control: no-cache, must-revalidate");  
header ("Pragma: no-cache");

10 thoughts on “Clear Browser Cache Using HTML or PHP”

  1. Actually, the PHP option is preferred when dealing with proxy caches. As most of them don’t read HTML in the requested document. Also, some browser caches don’t support the meta tags.
    The HTTP headers set by PHP aren’t stored in the HTML file, that way many more caches will interpret them.

  2. Haven’t seen a response to an earlier post – not working in Chrome or Safari. I also tried it in IE9 and can’t get this to work there either. Any comments on how to get it to work?
    thanks

  3. Hi There,

    We are looking use our htmls only work fine in any IE browsers. and it should cache user credentials.

    Requirement is everytime user tries to access link should pop-up for credentials. Even after writing code as mentioned below. Html is not asking for credentials.
    Can you please help in correcting the piece of code.

    #####################################


    #####################################

    Thanks,
    SD

Leave a Reply

Your email address will not be published. Required fields are marked *