Skip to content

Instantly share code, notes, and snippets.

@ruanyl
Last active August 29, 2015 14:05
Show Gist options
  • Save ruanyl/a0ca6bd48ccae24f694d to your computer and use it in GitHub Desktop.
Save ruanyl/a0ca6bd48ccae24f694d to your computer and use it in GitHub Desktop.
function set_headers($file, $timestamp) {
$gmt_mtime = gmdate('r', $timestamp);
header('ETag: "'.md5($timestamp.$file).'"');
header('Last-Modified: '.$gmt_mtime);
header('Cache-Control: public');
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime
|| str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == md5($timestamp.$file)) {
header('HTTP/1.1 304 Not Modified');
exit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment