2011-07-25 12 views
8

Soy la creación de mis encabezadoscontrol de caché y expira cabecera para PHP

$offset = 60 * 15; 

header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"); 
header("Cache-Control: max-age=$offset, must-revalidate"); 

Sin embargo cuando se ejecuta FireBug me facilita los siguientes datos de cabecera

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 

Alguien sabe por qué mis cabeceras no están siendo ¿Reconocido?

Respuesta

3

probar este

<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")); ?>"> 

o establecidos en las cabeceras de htaccess. También es necesario comprobar su archivo de configuración para apachi configration caché

+1

Esto está cerca. Sin embargo, debe usar gmdate() en lugar de date(). –

18

sé que algunas versiones atrás, Firebug tenían problemas y todas las solicitudes fueron 200 en lugar 304. Aquí está mi código, que estoy usando para 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 
    ?> 
Cuestiones relacionadas