0

For security reasons, several articles recommend "do not cache pages". So I usually put the following at the beginning of my web pages

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

That works very well, but many of the visitors likes to use the history buttons. So, I need to allow it for a short period. I tried to use the following headers

header("Cache-Control: maxage=".$expires.", must-revalidate");
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');

where $expires is the time I need. The problem is that pages do not expire, as if those headers were not there. How can I solve this?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
patocardo
  • 33
  • 6
  • please try this [session timeout](http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes) – maxjackie Jun 01 '12 at 12:09
  • Thanks maxjackie. I am already using session timeout, but my intention is to have a little browser-cache. – patocardo Jun 02 '12 at 17:29

1 Answers1

1

In short: Browser history caching is something different that you can not entirely control. There is a perfect and exhaustive answer to another question, that also answers your question over here:

Why both no-cache and no-store should be used in HTTP response?

Community
  • 1
  • 1
nico gawenda
  • 3,648
  • 3
  • 25
  • 38