Heim  >  Artikel  >  Backend-Entwicklung  >  PHP 网页过期时间的控制代码_PHP教程

PHP 网页过期时间的控制代码_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:45:151032Durchsuche

当然,前提要先打开CDN中一个功能reload_into_ims on.这样用户发送过来no-cache也不怕了.因为这样会给给no-cache转成If-Modified-Since .所以我们写程序主要是对If-Modified-Since控制就好了.记的,缓存系统架构中计中最好是后端来控制,所以最好的方法是程序来管理过期. 呵,我只会php,就用php写一个,别的程序也是一样。

见我下面的程序,呵呵,5分钟过期.

复制代码 代码如下:

$headers = apache_request_headers();
$client_time = (isset($headers['If-Modified-Since']) ? strtotime($headers['If-Modified-Since']) : 0);
$now=gmmktime();
$now_list=gmmktime()-60*5;
if ($client_time$now_list){
header('Last-Modified: ‘.gmdate('D, d M Y H:i:s', $client_time).' GMT', true, 304);
exit(0);
}else{
header('Last-Modified: ‘.gmdate('D, d M Y H:i:s', $now).' GMT', true, 200);
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/320344.htmlTechArticle当然,前提要先打开CDN中一个功能reload_into_ims on.这样用户发送过来no-cache也不怕了.因为这样会给给no-cache转成If-Modified-Since .所以我们写程序主...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn