0

I have an HTML page that has shows if a server is online of offline via an IFRAME transcluding a php file.

If someone clicks on a link, like to turn the server on or off and presses the Back button on the browser, the browser loads a cached version of the page and still displays the server as "off" unless the page is refreshed. I know there are other ways to go about this but I would like for just that page to not be cached so that when a user reaches that page via the Back button, it will have to redownload the page.

How can this be done? Is it even possible?

Putting header("Cache-Control: no-cache, must-revalidate"); in the php file did not work.

1 Answer 1

1

Of course it is possible. Try sending these headers in your PHP code:

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Expires: Tue, 1 Jan 1980 00:00:00 GMT

The Expires header can have any valid date in the past (preferably quite few years back, in case system time on that PC is set in the past as well).

These headers work fine for me in all browsers (I remember testing them 3 or 4 years ago in IE 6, Firefox 2, Opera 9, Safari 4).

23
  • I'm excited it works :) However by putting these on my php file didn't work header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); header("Pragma: no-cache"); header("Expires: Thu, 1 Jan 1980 00:00:00 GMT");
    – dukevin
    Commented Sep 12, 2011 at 1:03
  • @Kevin Possibly because of wrong date: 01/01/1980 was Tuesday and not Thursday (my bad -- typo). Make sure you are using correct date any way. Also try restarting browser after clearing caches (it should not really affect browser .. just in case). Apart of that -- it should work (definitely works fine for me on basket/shopping cart pages) -- maybe it's affected by iframe thing .. not sure.
    – LazyOne
    Commented Sep 12, 2011 at 1:25
  • Nope, still no luck :( I have a little demo here so you can try it out: 109.169.58.107/test/sand/status.html pressing on the on/off buttons will make it say offline or online but only if you press the refresh on your browser after it redirects. You can view the source files here: 109.169.58.107/test/sand
    – dukevin
    Commented Sep 12, 2011 at 7:13
  • I added your header on the php files and all the html files with <META HTTP-EQUIV ...>
    – dukevin
    Commented Sep 12, 2011 at 7:22
  • 1
    @Kevin I have also run the same on another PC, clean Firefox profile .. and does not work here. It does work fine when I install Firebug and watch the Net panel, but when hidden .. it does not always work. I have also installed httpFox extension for Firefox, and when Firebug is off ... it looks like Firefox is not bothered to request the status page again -- the last page is POST page, not GET. I'm puzzled ATM (have not look at your code yet).
    – LazyOne
    Commented Sep 12, 2011 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.