Skip to content

Instantly share code, notes, and snippets.

@Igor-Lopes
Created November 3, 2017 18:03
Show Gist options
  • Save Igor-Lopes/57b1e0dd953482ceae19e4072fc54b60 to your computer and use it in GitHub Desktop.
Save Igor-Lopes/57b1e0dd953482ceae19e4072fc54b60 to your computer and use it in GitHub Desktop.
<?php
$file = 'myfile.php';
$last_modified_time = filemtime($file);
$etag = md5_file($file);
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
header("Etag: $etag");
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time ||
trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
header("HTTP/1.1 304 Not Modified");
exit;
}
?>
@carlosalbertocruz
Copy link

function set_cache($content) {
$etag = md5(serialize($content));

header("Etag: $etag");
if ($_SERVER['HTTP_IF_NONE_MATCH'] && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
    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