I use expiring urls to hide the urls of images I use on my sites, so that they can only be hotlinked for the duration of the life of the hash (1 hour).
I check the hash sent with the file url, against a hash on the server, if they match, the script calls the following code:
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;
}
}
I use this in an tag (for example, <img src="index.php?id=123&hash=ew6rg5reg4">
and it works perfectly. If the image is hotlinked, it will stop working when the hash changes, every hour (or minute if necessary). Unfortunately, this same method doesn't work when I use it to load .flv files into a flash player, such as the JW player . No .flv file is loaded.
Any way I can fix this or achieve the same thing with an alternate method?