lastmod
header(last_modified());
function last_modified() {
$file = './lastmod.json';
$current_date = gmdate("Ymd");
if (file_exists($file)) {
$json = file_get_contents($file);
$lm_dates = json_decode($json);
/**
http://sitename.ru/
http://sitename.ru/ishop/70
http://sitename.ru/site/4
http://sitename.ru/site/7
http://sitename.ru/site/8
*/
$reg_exp = '/^(\/(ishop\/70|site\/(4|7|8))?)$/';
if (preg_match($reg_exp, $_SERVER['REQUEST_URI'])) {
$type = 'daily';
$num_of_days = 1;
} else {
$type = 'weekly';
$num_of_days = 7;
}
$date = $lm_dates->$type->date;
if (($current_date - $date) >= $num_of_days) {
$lm = "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT";
$lm_dates->$type->date = $current_date;
$lm_dates->$type->string = $lm;
file_put_contents($file, json_encode($lm_dates));
} else {
$lm = $lm_dates->$type->string;
}
} else {
$lm = "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT";
$dates = array(
'daily' => array('date' => $current_date, 'string' => $lm),
'weekly' => array('date' => $current_date, 'string' => $lm)
);
file_put_contents($file, json_encode($dates));
}
return $lm;
}