PHP高级应用学习笔记之 利用header()函数设置浏览器缓存 这涉及到4种头标类型:
<?php # Script 2.7 - view_tasks.php // Connect to the database: $dbc = @mysqli_connect ('localhost', 'username', 'password', 'test') OR die ('<p>Could not connect to the database!</p></body></html>'); // Get the latest dates as timestamps: $q = 'SELECT UNIX_TIMESTAMP(MAX(date_added)), UNIX_TIMESTAMP(MAX(date_completed)) FROM tasks'; $r = mysqli_query($dbc, $q); list($max_a, $max_c) = mysqli_fetch_array($r, MYSQLI_NUM); // Determine the greater timestamp: $max = ($max_a > $max_c) ? $max_a : $max_c; // Create a cache interval in seconds: $interval = 60 * 60 * 6; // 6 hours // Send the header: header ("Last-Modified: " . gmdate ('r', $max)); header ("Expires: " . gmdate ("r", ($max + $interval))); header ("Cache-Control: max-age=$interval"); ?>
$interval=60*60*6
header("Last-Modified:".gmdate("r",($max+$interval)));
header ("Expires: " . gmdate ("r", ($max + $interval)));
header ("Cache-Control: max-age=$interval"); |