Last active
August 29, 2015 14:05
-
-
Save ruanyl/a0ca6bd48ccae24f694d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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