0

Right now we have a 1 month developing cycle for our web based service. Is it possible to set the headers so the cache will expire the 1st of every month for all users? I know that we could set the expiration date to the 1st next month every time we make an update but I would want a more flexible solution. So in short, can I in some way do this?

header("Expires: 1st/month 05:00:00 GMT"); // Expires the 1st of every month for everybody
BartoszKP
  • 34,786
  • 15
  • 102
  • 130

1 Answers1

2

Use the code from this other StackOverflow question to get a timestamp for the first day of the next month:

$curMonth = date('n');
$curYear  = date('Y');

if ($curMonth == 12)
    $firstDayNextMonth = mktime(0, 0, 0, 0, 0, $curYear+1);
else
    $firstDayNextMonth = mktime(0, 0, 0, $curMonth+1, 1);

Then, use that timestamp with date() to generate the date in the format required by the HTTP Expires header:

header('Expires: ' . date('D, d M Y', $firstDayNextMonth) . ' 05:00:00 GMT');
Community
  • 1
  • 1
Trott
  • 66,479
  • 23
  • 173
  • 212