2010-11-19 55 views

回答

3
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

php::header() resource

你將要使用:

//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 
+0

是的,我會感謝一些幫助getTimeUntil2AM – Josh12 2010-11-19 17:30:33

0

您可以使用strtotime凌晨2點,以獲得Unix時間戳和減去從當前時間:

$diff = strtotime('2 AM') - time(); 
if ($diff < 0) $diff += 86400; 

你然後可以使用該差異作爲Cache-Control最大年齡

header('Cache-Control: max-age='.$diff); 
0

設置過期 -HTTP報頭(爲示例,請參見Wikipedia)與header()。你只需要指定日期。

header("Expires: " . date('D, d M Y') . " 02:00:00 GMT"); 

date()

請注意,這是北京時間。你可能想要設置另一個時區。

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));