GMT $lastmodified = date("D, d M Y H:i:s", $lastmod) . " GMT"; # ETag is "inode-lastmodtime-filesize" - See PHP stat function for more detail $etag = 'W/"' . dechex($filestats[1]) . "-" . dechex($lastmod) . "-" . dechex($filestats[7]) . '"'; # Check HTTP_IF_NONE_MATCH # and report a 304 Not Modified header if they match. if (isset ($_SERVER["HTTP_IF_NONE_MATCH"])) { if ($etag === stripslashes($_SERVER["HTTP_IF_NONE_MATCH"])) $is304 = true; } # Check HTTP_IF_MODIFIED_SINCE # and report a 304 Not Modified header if they match. if ((isset ($_SERVER["HTTP_IF_MODIFIED_SINCE"]))) { #Old Netscape and/or IE can put "; length=xyz" after the "GMT" in date #which completly violates the specs, so we have to strip it out. if (preg_replace('/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"]) === $lastmodified) $is304 = true; } # Get max age in seconds. $max_age = $max_age_minutes * 60; header("Cache-Control: max-age=$max_age, s-maxage=$max_age"); header("Expires: " . date("D, d M Y H:i:s",time() + $max_age - date('Z')) . " GMT"); header("X-PHP-Caching: 1.0.1"); # If for some reason we didn't get a valid file modification time # from the stat function, or it errored out, DO NOT send the ETag # header as it will not be valid. Valid in this since is defined # as modified AFTER Dec 24, 1999. if ($lastmod > 946080000) { # 946080000 = Dec 24, 1999 4PM header("ETag: " . $etag); header("Last-Modified: " . $lastmodified); } if ($is304) { if (isset($_SERVER["SERVER_PROTOCOL"]) && $_SERVER["SERVER_PROTOCOL"] == "HTTP/1.1") header("HTTP/1.1 304 Not Modified"); else header("HTTP/1.0 304 Not Modified"); header("Connection: close"); exit; } header("Content-Type: $mime;charset=$charset"); ?>