Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP的缓存控制和expires标头_Php_Caching_Http Headers_Cache Control - Fatal编程技术网

PHP的缓存控制和expires标头

PHP的缓存控制和expires标头,php,caching,http-headers,cache-control,Php,Caching,Http Headers,Cache Control,我正在设置标题 $offset = 60 * 15; header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"); header("Cache-Control: max-age=$offset, must-revalidate"); 但是,当运行FireBug时,它会给我以下标题信息 HTTP/1.1 200 OK Date: Mon, 25 Jul 2011 12:15:12 GMT Server:

我正在设置标题

$offset = 60 * 15;

header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
header("Cache-Control: max-age=$offset, must-revalidate"); 
但是,当运行FireBug时,它会给我以下标题信息

HTTP/1.1 200 OK
Date: Mon, 25 Jul 2011 12:15:12 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9
X-Powered-By: PHP/5.2.9
Expires: Sat, 01 Jan 2000 00:00:01 GMT
Cache-Control: post-check=0, pre-check=0, max-age=0
Pragma: no-cache
Last-Modified: Mon, 25 Jul 2011 12:15:13 GMT
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
有人知道为什么我的标题没有被识别吗

试试这个

<META HTTP-EQUIV="Pragma" CONTENT="private">
<META HTTP-EQUIV="Cache-Control" CONTENT="private, max-age=5400, pre-check=5400">
<META HTTP-EQUIV="Expires" CONTENT="<?php echo date(DATE_RFC822,strtotime("1 day")); ?>">


我知道几个版本之前,Firebug有问题,所有请求都是200而不是304。这是我的代码,我正在使用css:

    <?php
    if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
      $if_modified_since = preg_replace('/;.*$/', '',   $_SERVER['HTTP_IF_MODIFIED_SINCE']);
    } else {
      $if_modified_since = '';
    }

    $mtime = filemtime($_SERVER['SCRIPT_FILENAME']);
    $gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';

    if ($if_modified_since == $gmdate_mod) {
      header("HTTP/1.0 304 Not Modified");
      exit;
    }

    header("Last-Modified: $gmdate_mod");
    header('Content-type: text/css');

    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (60*60*24*45)) . ' GMT');
    // rest of the code
    ?>

这很接近。但是,您应该使用gmdate()而不是date()。