Created
June 4, 2018 18:11
-
-
Save dryks/47779c79344fc4ae3f645d5ed1bf8491 to your computer and use it in GitHub Desktop.
Отдача HTML заголовков 304 Not Modified LastModified на PHP
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 | |
//взято отсюда https://habr.com/sandbox/75204/ | |
//проверка заголовков https://last-modified.com | |
$LastModified_unix = $timetime; // время последнего изменения страницы | |
$LastModified = gmdate(«D, d M Y H:i:s \G\M\T», $LastModified_unix); | |
$IfModifiedSince = false; | |
if (isset($_ENV['HTTP_IF_MODIFIED_SINCE'])) | |
$IfModifiedSince = strtotime(substr($_ENV['HTTP_IF_MODIFIED_SINCE'], 5)); | |
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) | |
$IfModifiedSince = strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 5)); | |
if ($IfModifiedSince && $IfModifiedSince >= $LastModified_unix) { | |
header($_SERVER['SERVER_PROTOCOL']. ' 304 Not Modified'); | |
exit; | |
} | |
header('Last-Modified: '. $LastModified); | |
header('Content-type: text/html; charset=utf-8'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment