Z
Z
ZakkMalin2019-07-15 09:45:58
PHP
ZakkMalin, 2019-07-15 09:45:58

How often does Last-Modified change?

Helped one person with the question Why do search engines not see the full title?
I advised him to look towards Last-Modified,
but I don’t know if he wrote the code correctly so that the date does not change with each generation, but only when the content on the page actually changes, can you inspect the code that he provided on Smarty:

$LastModified_unix = strtotime(date("D, d M Y H:i:s", filectime($_SERVER['SCRIPT_FILENAME']))); 
$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);

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Skibin, 2019-07-15
@ZakkMalin

filectime($_SERVER['SCRIPT_FILENAME'])
You're reading the modification date of a file, not a database entry or something. You need to understand which elements in the content area can change and take their modification date.
For a static page - the maximum modification date from all text blocks
For a catalog - the maximum modification date from all elements (or we fix it for the catalog itself)
For a filter - always current
For an element - the date the element was modified

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question