Y en este POST, una versión mejorada de el anterior.
Notar que hay una parte en donde tengo que agregar 21600 segundos, es decir, le aumento 6 horas porque vivo en en México y aquí estamos en la hora GMT -06.
Para el efecto inverso (cuando el navegador envía la cabecera IF-MODIFIED-SINCE) la función
strtotime() automáticamente resta esas 6 horas y la convierte en UNIX timestamp (toma eso en cuenta si tu servidor no tiene la misma hora de tu país).
Código PHP:
<?
//
function cacheando($archivo){
$ultima_modificacion = "";
if(file_exists($archivo)){
$timestamp_archivo = filemtime($archivo);
}//end file_exists
else mensaje_final('badcache2'); //archivo no existe
//convertimos la cabecera del navegador a UNIX Time Stamp para comparar
$timestamp_navegador = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
//colocamos estas cabeceras SIEMPRE y antes de mandar o no el 304
header("Cache-Control: max-age=0, must-revalidate");
header("Pragma: no cache");
header("Last-Modified: ".date("D, d M Y H:i:s",$timestamp_archivo + 21600)." GMT"); //21600 segundos = 6 hrs. (por ser Mexico City)
//si las fechas son idénticas (navegador y servidor)
if($ultima_modificacion == $timestamp_navegador){
header("HTTP/1.1 304 Not changed");
exit;
}//end if
}//end function
?>
Un saludo !