Question

I want to prevent the user from pressing going to the previous page (back button in browser), after logout.

I manage to do this in apache adding this to the configuration:

<FilesMatch "\.(html|htm|js|css|pl)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</FilesMatch>

But when i do it directly in the sources it doesnt work i'm using:

<meta content="no-cache" http-equiv="Pragma"></meta>
<meta content="no-cache, no-store, must-revalidate" http-equiv="Cache-Control"></meta>
<meta content="0" http-equiv="Expires"></meta>
Was it helpful?

Solution

As Quentin exlplain this meta tags are ignored by the browser.

<meta content="no-cache" http-equiv="Pragma"></meta>
<meta content="no-cache, no-store, must-revalidate" http-equiv="Cache-Control"></meta>
<meta content="0" http-equiv="Expires"></meta>

So this is what worked for me to disable the cache in all browsers.

From perl

 Use CGI;

 sub set_new_query() {
            $query = CGI->new();
            print $query->header(
                            -expires       => 'Sat, 26 Jul 1997 05:00:00 GMT',
                            -Pragma        => 'no-cache',
                            -Cache_Control => join(', ', qw(
                                                private
                                                no-cache
                                                no-store
                                                must-revalidate
                                                max-age=0
                                                pre-check=0
                                                post-check=0 
                                               ))
            );
        }

An alternative in Apache is to add to httpd.conf:

LoadModule headers_module modules/mod_headers.so

<FilesMatch "\.(html|htm|js|css|pl)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</FilesMatch>

And for other language here is a great description: Making sure a web page is not cached, across all browsers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top