Skip to content

Instantly share code, notes, and snippets.

@Stanback
Created October 27, 2014 17:19
Show Gist options
  • Save Stanback/7b3a9b8e54cc63f5daaa to your computer and use it in GitHub Desktop.
Save Stanback/7b3a9b8e54cc63f5daaa to your computer and use it in GitHub Desktop.
Example of date-based browser caching
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= filemtime($path_to_image)) {
header('HTTP/1.0 304 Not Modified');
header('Cache-Control: public, max-age=2592000');
header('Last-Modified: Mon, 27 Oct 2014 17:08:41 GMT');
exit(0);
} else {
header('Content-type: image/jpeg');
header('Cache-Control: public, max-age=2592000');
header('Last-Modified: Mon, 27 Oct 2014 17:08:41 GMT');
echo file_get_contents($path_to_image);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment