Last-Modified and $_SERVER how does it work?

The challenge is to set Last-Modified on the website. Of course go to the website last-modified.com and copy the code from there.
<?php
$LastModified_unix = 1294844676; // time of last modification of the page
$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);
?>

But it turns out to work. verdampen on the test page $_ENV and $_SERVER. Find that the first is completely empty, the second array does not contain a variable for the key ['HTTP_IF_MODIFIED_SINCE'].
Here recall that there is another website. where the ill-fated Last-Modified works as it should. Go there and see there is exactly the same code as given above. There verdampen the same variables and...
And there the result is identical. The first array is empty, and in the second there is nothing on the key ['HTTP_IF_MODIFIED_SINCE']. Why on one site the code works and gives the desired header, and the other not?
July 2nd 19 at 17:08
1 answer
July 2nd 19 at 17:10
> Of course go to the website
Of course to go to the website php.net and study there to learn the titles in Wikipedia, but not on govnosayte that shows some crap
Who will smoke if in the top of the website with the finished snippet. Set and forget.
Offer snippet better? - everett.Gaylord7 commented on July 2nd 19 at 17:13
: well then step on a rake, if you set and forget the - mina50 commented on July 2nd 19 at 17:16
Well, I just asked... I like the rules work this on different hostings.
What's wrong with this? Maybe there is something better?
That's really don't want to reinvent the wheel. - everett.Gaylord7 commented on July 2nd 19 at 17:19
OK if you look and Google it
this thing installs a web server to php
for example Apache
RewriteEngine on
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]

well I say, why not just use the headers and not bother crap from third party sites? :) - mina50 commented on July 2nd 19 at 17:22
Damn z negjq(
And how to glue together?
header Last-Modified, then I calculate in php... - everett.Gaylord7 commented on July 2nd 19 at 17:25
: a part from Apache to .htaccess
and the fact that in PHP, and will remain there - mina50 commented on July 2nd 19 at 17:28
your variant I have seen on open spaces. In my case it is why it causes the error. The site stops responding at all, or gives 500. I'm not good at backend, but according to the admin there's a mixture of apache and nginx - Craig70 commented on July 2nd 19 at 17:31
: no rewritelog and all your .htaccess is to get a finger to the sky. - mina50 commented on July 2nd 19 at 17:34
: I have this option works standards (also +nginx). But I had to leave did not, as MNU, and without him everything is OK.

Heh, as the previous hosting had simply register only the header Last-Modified, the rest he did himself.. it was pretty cool. - everett.Gaylord7 commented on July 2nd 19 at 17:37

Find more questions by tags PHP