2011-06-02 177 views
6

我正在生成圖像,並希望瀏覽器將其永久緩存,但瀏覽器永遠不會緩存它們。 這是我的PHP代碼強制瀏覽器緩存圖像


header('Content-type:'.$file->content_type); 
header('Expires: Thu, 15 Apr '.(date('Y')+10).' 20:00:00 GMT'); 
header('Content-Disposition: attachment; filename="'.$file->file_name.'"'); 
echo(file_get_contents($model_files->files_path.$file->md5.$model_files->seprator.$file->file_name)); 

,這些都是響應頭,我不斷收到在瀏覽器中。

Date:   Thu, 02 Jun 2011 12:56:56 GMT 
Server:   Apache mod_fcgid/2.3.6 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 
X-Powered-By  PHP/5.2.15 
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Pragma   no-cache 
Expires   Thu, 15 Apr 2021 20:00:00 GMT 
Content-Length 321823 
Keep-Alive  timeout=5, max=100 
Connection  Keep-Alive 
Content-Type  image/png

我不是設置日期,緩存控制和Pragma,但不斷得到他們的迴應。

我知道我可以覆蓋他們,但老實說,我不完全知道要設置的值。

+0

你找到答案了嗎? – 2018-01-29 00:17:22

回答

0

您可以使用:

header('Cache-Control: max-age=37739520, public'); 

你可以嘗試覆蓋附註太多,但我認爲這一天瀏覽器只是忽略附註如果緩存控制是isset。

header('Pragma: public'); 
+0

謝謝,請讓我試試 – 2011-06-02 13:19:19

+0

對不起,沒有工作 – 2011-06-03 11:30:35

2
+0

+1如果您在此頁面上使用session_start,這可能是緩存標題的原因。如果你不需要會話,只需刪除session_start即可。如果你不使用它,請在你的問題中提及它,你需要追查這些標題的其他原因。 – Mel 2011-06-02 13:34:58