I
I
Ilya Beloborodov2017-08-14 19:29:22
PHP
Ilya Beloborodov, 2017-08-14 19:29:22

LastModified not working?

I've been messing around with LastModified all day. There is such

<?php
$LastModified_unix = 1294844676; // время последнего изменения страницы
$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);
?>

For the life of me, the response is always 200 Ok instead of the desired 304. I wrote
in htaccess
RewriteEngine on
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]

like peas against the wall

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2017-08-14
@kowap

Have you looked at the request headers? Perhaps the browser does not send you IF_MODIFIED_SINCE, or you perform the request 1 time, read how it works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question