ecco una domanda opposta a quella che si vede tutti i giorni.![]()
Senza fare un sistema di caching ad hoc, esiste un header http che forzi il browser ad usare una pagina (php) con lo stesso nome e stessa querystring che sia già in cache?
ciao,
jack.
ecco una domanda opposta a quella che si vede tutti i giorni.![]()
Senza fare un sistema di caching ad hoc, esiste un header http che forzi il browser ad usare una pagina (php) con lo stesso nome e stessa querystring che sia già in cache?
ciao,
jack.
Ciao,
ci sono diversi sistemi, uno te lo suggerisce il sorgente di www.php.net
http://www.php.net/source.php?url=/index.php
in particolare questo pezzo
// Note that this is not a RFC 822 date (the tz is always GMT)
$tsstring = gmdate("D, d M Y H:i:s ", $timestamp) . "GMT";
// Check if the client has the same page cached
if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) &&
($_SERVER["HTTP_IF_MODIFIED_SINCE"] == $tsstring)) {
header("HTTP/1.1 304 Not Modified");
exit();
}
// Inform the user agent what is our last modification date
else {
header("Last-Modified: " . $tsstring);
}
per favore NIENTE PVT TECNICI da sconosciuti
è esattamente quello che cercavo, ma purtroppo non esiste if $_SERVER['HTTP_IF_MODIFIED_SINCE']...
Dovrebbe essere data da apache questa var? perchè non c'è...
Oppure suggerivi di usare direttamente l'header 304? Intanto sto dando un'occhiata al sito php.
EDIT:
credo mi sia utile una cosa del genere, serve anche a me per le immagini in db. dai commenti in php.net: (qui non mi va l'header 'If-None-Match', vedi http://www.w3.org/Protocols/rfc2616/rfc2616)
How to force browser to use already downloaded and cached file.
If you have images in DB, they will reload each time user views them. To prevent this, web server must identify each file with ID.
When sending a file, web server attaches ID of the file in header called ETag.
header("ETag: \"uniqueID\");
When requesting file, browser checks if the file was already downloaded. If cached file is found, server sends the ID with the file request to server.
Server checks if the IDs match and if they do, sends back
header("HTTP/1.1 304 Not Modified");
else
Server sends the file normally.
codice:<?php $file = getFileFromDB(); // generate unique ID $hash = md5($file['contents']); $headers = getallheaders(); // if Browser sent ID, we check if they match if (ereg($hash, $headers['If-None-Match'])) { header('HTTP/1.1 304 Not Modified'); } else { header("ETag: \"{$hash}\""); header("Accept-Ranges: bytes"); header("Content-Length: ".strlen($file['content'])); header("Content-Type: {$mime}"); header("Content-Disposition: inline; filename=\"{$file['filename']}\";"); echo $file['content']; } exit(); ?>
up.![]()