Comment puis-je paramétrer l'expiration du document tous les jours à 2h du matin en PHP?L'en-tête php expire tous les jours à X
1
A
Répondre
3
header("Expires: " . date("D, j M Y", strtotime("now")) . " 02:00:00 GMT");
ou
header("Expires: " . date("D, j M Y", strtotime("tomorrow")) . " 02:00:00 GMT");
1
Vous voulez utiliser:
//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
oui, j'apprécierais de l'aide avec getTimeUntil2AM – Josh12
0
Vous pouvez utiliser strtotime
pour obtenir l'horodatage Unix à 2 heures et soustrayez à partir du moment actuel:
$diff = strtotime('2 AM') - time();
if ($diff < 0) $diff += 86400;
Vous peut alors utiliser cette différence pour Cache-Controlmax-age:
header('Cache-Control: max-age='.$diff);
0
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));
Merci à tous! – Josh12