Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Firefox, NOT cache my webpage

I have this page, let's call it index.php

index.php has a list of users and a remove user button. That will take them to removeUser.php

And the last line of removeUser.php is to go back to index.php

But in Firefox, it still looks the same, a normal user won't know how to do a hard-refresh or clear the cache every time the page loads manually.

I have tried

CACHE-CONTROL NO-CACHE,NO-STORE

and also

PRAGMA NO-CACHE,NO-STORE

I even tried setting EXPIRY 0 in the META tags, none of these help. Although it all works perfectly in Chrome and other browsers, it's just Firefox that has this problem.

These are my headers, requested by @alex

http://localhost/xChange/home.php

GET /xChange/home.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://localhost/xChange/home.php
Cookie: laobgcidne=yes; [email protected]
Cache-Control: max-age=0

HTTP/1.1 200 OK
Date: Fri, 10 Dec 2010 08:28:25 GMT
Server: Apache/2.2.11 (Win32) PHP/5.3.0
X-Powered-By: PHP/5.3.0
Cache-Control: no-cache, must-revalidate
Expires: Sat, 26 Jul 1997 05:00:00 GMT
Content-Length: 6130
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
like image 954
Nareshkumar Rao Avatar asked Dec 06 '22 00:12

Nareshkumar Rao


2 Answers

Send a expires header for a date in the past.

Example

header("Cache-Control: no-cache, must-revalidate"); 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

Source.

Update

Your headers look pretty good. I don't know what Firefox is doing.

You could do this on the link, to make sure it always downloads a fresh copy.

<?php $link = 'home.php'; ?>
<a href="<?php echo $link . '?m=' . filemtime($link); ?>">Home</a>
like image 119
alex Avatar answered Dec 08 '22 04:12

alex


  • First maybe your curl --head index.php summary could help us.

  • This explains caching in full detail: http://www.mozilla.org/projects/netlib/http/http-caching-faq.html.

  • use http://nl.php.net/manual/en/function.header.php to set headers.

  • Also have look at Etag, If-None-Match, Last-Modified, if-modified-since

  • Or if it really does not work you could timestamp your urls

    index.php?<?= echo time(); ?>

like image 23
Alfred Avatar answered Dec 08 '22 04:12

Alfred