用php控制页面的过期时间

yibin 2015-02-09 建站源码 662

用php控制页面的过期时间:
    控制页面的过期主要是对If-Modified-Since控制.
    下面的程序实现页面5分钟后过期
    <?php
    $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 and $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);
    }
    ?>

扫码添加微信

13013082126 扫描微信 建站咨询 优化咨询