【发布时间】:2017-04-20 16:36:17
【问题描述】:
我有一个生成 *.png 图片但 不 将它们存储在服务器上的 php 脚本。这些图片将重复显示给同一用户。我正在寻找一种方法来缓存这些图片。我可以发送 304 状态标头,浏览器还会在第一次刷新时将网页声明为缓存(因为它在 web-inspector 中可见),但网页显示为空白。在第二次刷新后,甚至 web-inspector 也显示为空白。
谁能帮我看看我哪里搞砸了?
注意事项:
- 我读过this post,但对我没有帮助。
- 使用 MAMP(PHP 版本 7.0.10)
- 我是新手,对于丑陋的代码,我深表歉意。
以下是文件的主要行:
session_start();
header("Content-type: image/jpeg");
//A little require_once() here on some functions stored in an other file.
$originalSource = getSource($_GET['src']);
if (isset($_COOKIE[sha1($originalSource)]) && $_COOKIE[sha1($originalSource)]) {
header("HTTP/1.1 304 Not Modified");
die;
} else {
setcookie (sha1($originalSource), true, time()+10);
$offset = 10;
$expire = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
header($expire);
header("Cache-Control: max-age=".$offset);
header("Last-Modified: Wed, 25 Feb 2015 12:00:00 GMT");
}
//The entire image generation process after this
谢谢你的帮助????
【问题讨论】: