Expiration in php

A server can explicitly inform the browser, and any proxy caches that might be between the server and browser, of a specific date and time for the document to expire. Proxy and browser caches can hold the document until that time or expire it earlier. Repeated reloads of a cached document do not contact the server. However, an attempt to fetch an expired document does contact the server.

To set the expiration time of a document, use the Expires header:

header(“Expires: Fri, 18 Jan 2006 05:30:00 GMT”);

To expire a document three hours from the time the page was generated, use time() and gmstrftime() to generate the expiration date string

$now = time();
$then = gmstrftime(“%a, %d %b %Y %H:%M:%S GMT”, $now + 60 * 60 * 3);
header(“Expires: {$then}”);

Leave a Comment