Created
October 27, 2014 17:19
-
-
Save Stanback/7b3a9b8e54cc63f5daaa to your computer and use it in GitHub Desktop.
Example of date-based browser caching
This file contains 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
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