Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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).

share|improve this answer
    
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"); –  Kevin Duke Sep 12 '11 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 Sep 12 '11 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 –  Kevin Duke Sep 12 '11 at 7:13
    
I added your header on the php files and all the html files with <META HTTP-EQUIV ...> –  Kevin Duke Sep 12 '11 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 Sep 12 '11 at 9:02
show 18 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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