【发布时间】:2009-02-17 20:49:36
【问题描述】:
我使用过期网址来隐藏我在我的网站上使用的图片的网址,以便它们只能在哈希的生命周期(1 小时)内进行热链接。
我检查与文件 url 一起发送的哈希值,与服务器上的哈希值相匹配,如果它们匹配,脚本将调用以下代码:
if (isset($_GET["hash"])) {
$this_min = date('Y-m-d-g',time()) . "salt" . $vid_id;
$current_hash = substr(md5($this_min),0,12);
$submitted_hash = mysql_real_escape_string($_GET["hash"]);
if ("$current_hash" == "$submitted_hash") {
$file_url2 = "directory/" . $vid_file;
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: inline; filename=\"".md5($vid_file)."\"");
readfile($file_url2);
exit;
} else {
$_SESSION["message"] = "Download link expired, refresh the page and try again";
$_SESSION["message_type"] = 0;
header("Location:" . $_SERVER['HTTP_REFERER']);
exit;
}
}
我在标签中使用它(例如,<img src="index.php?id=123&hash=ew6rg5reg4">,它工作得很好。如果图像是热链接的,它会在哈希更改时停止工作,每小时(或必要时每分钟)。不幸的是,这种方法相同当我使用它加载.flv 文件到flash 播放器时不起作用,例如JW 播放器。没有加载.flv 文件。
我有什么方法可以解决这个问题或使用替代方法实现相同的目标?
【问题讨论】:
-
如果有人在 6 点 59 分 45 分下载您的网页,但连接速度很慢,那么大多数嵌入的图像将无法加载,我是否理解正确?这似乎不太幸运......