Forum Moderators: coopster
can somebody please help:
I am trying to force the back-button to re-load a page in IE, but even the following basic script, based on [uk.php.net...] is not working:
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
$timenow = time();
echo date("r",$timenow);
?>
I'm using php 4.3.4
(Note that the ASP script at [support.microsoft.com...] does work, but I haven't been able to successfully combine it with my existing php code).
Am I missing something very basic here? Any help appreciated!
Thanks in advance.
Are you getting any errors either output to the browser or in your error logs? It could be that the headers aren't being sent properly to the browser because a text character was sent before the call to the function. Make sure you have no text, whitespace, etc... before the header() function otherwise it won't work.
One last thing. Is this happening only with Internet Explorer or it an issue all around?
Hopefully these suggestions will lead to your answer! :)
thanks for that.
1) checking access logs, I have HTTP code 200, so looks ok.
The correctly working .ASP file also gives code 200. (Obviously the .ASP is logged as 2 requests, as the back button is preventing caching - the PHP code only logs 1 request as it is pulling from the cache the second time).
2) white space, etc: my code is exactly as shown above, i.e. stripped down to the bare minimum, so unless I'm missing something I can't see how anything would have been sent in advance of the header.
3) Firefox 2.0 and 2.0.0.3: neither the PHP or ASP worked correctly in either version of Firefox - both are allowing caching.
This is really puzzling me ... the script is so simple there should be nothing to go wrong.
Any further thoughts much appreciated.
The problem is with the back button - a user clicking on this (even after logging out) will be able to see the cached pages.
(The example in my original post is a simplified version without the meta tags or anything else, but it still has the same problem of allowing caching).
GET is not for doing anything which changes something serverside - so it should never matter that the user can go backwards. GET is for 'getting' information only - not for changing it.
POST is for changing things - giving new information or instructions to edit the contents of the database or similar.
If you stick to those guidelines then you shouldn't have a problem with allowing use of the back button.
Header( "Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
Header( "Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT" );
Header( "Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1
Header( "Cache-Control: post-check=0, pre-check=0", FALSE );
Header( "Pragma: no-cache" ); // HTTP/1.0
I tried the POST idea, but it didn't seem to help.
Same for the other headers, and also for
Header( "Cache-control: private", FALSE );
Apparently my original code does prevent caching in IE7, but not in IE6.
Will include all these headers anyway, in the hope that at least they work in some browsers some of the time, but have to accept that I can't depend on them.
Anyway, thanks for the ideas.