Last active
February 12, 2019 10:09
-
-
Save ivansky/c020f7d9dfd39fb6aac1 to your computer and use it in GitHub Desktop.
PHP 304 Last Modified Example
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
# Bitrix Example | |
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-l | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_FILENAME} !/bitrix/urlrewrite.php$ | |
RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L] | |
#RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}] | |
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}] |
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
<?php | |
$LastModifiedTime = 0; // < == SOME TIMESTAMP WHEN MODIFIED | |
$LastModified = date('D, d M Y H:i:s') . ' GMT'; | |
$IfModifiedSince = isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : 0; | |
$IfModifiedSinceTime = strtotime($IfModifiedSince); | |
if ($IfModifiedSince && preg_match('/[0-9]{2,}\s+[a-z]{2,}\s+[0-9]{4}\s[0-9]{2}:[0-9]{2}:[0-9]{2}/i', $IfModifiedSince) && $LastModifiedTime > $IfModifiedSinceTime){ | |
$sapi_name = php_sapi_name(); | |
if (strrpos($sapi_name, 'cgi') === 0){ | |
header('Status: 304 Not Modified'); | |
}else{ | |
header('HTTP/1.1 304 Not Modified'); | |
} | |
exit; | |
} | |
header('Last-Modified: ' . $LastModified); | |
/* ... contents of file ... */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment