如何将文档设置为每天凌晨2点在PHP中过期?
答案 0 :(得分:4)
header("Expires: " . date("D, j M Y", strtotime("now")) . " 02:00:00 GMT");
或
header("Expires: " . date("D, j M Y", strtotime("tomorrow")) . " 02:00:00 GMT");
答案 1 :(得分:1)
您将要使用:
//assuming getTimeUnitl2AM() returns time in seconds until 2am
//if you need help implementing a function that returns
//time until 2am ask
$time = getTimeUntil2AM();
header("Expires: $time"); // set expiration time
答案 2 :(得分:1)
// 2AM today
$epoch = mktime(2,0,0,date('n'),date('j'),date('y'));
// Go to tomorrow if current time > 2AM
$epoch += date('H') >= 2 ? 86400 : 0;
// Send header with RFC 2822 formatted date
header('Expires: '.date('r', $epoch));
答案 3 :(得分:0)
您可以使用strtotime
在凌晨2点获取Unix时间戳并从当前时间减去该时间戳:
$diff = strtotime('2 AM') - time();
if ($diff < 0) $diff += 86400;
然后,您可以将此差异用于Cache-Control的 max-age :
header('Cache-Control: max-age='.$diff);
答案 4 :(得分:0)