您需要使用 php 文件(或其他替代文件)动态提供 URL,它必须是服务器端代码,并且看起来像
<?php
$hash = $_GET['h'];
$streamname = $_GET['v'];
$timestamp = $_GET['t'];
$current = time();
$token = 'sn983pjcnhupclavsnda';
$checkhash = md5($token . '/' . $streamname . $timestamp);
if (($current - $timestamp) <= 2 && ($checkhash == $hash)) {
$fsize = filesize($streamname);
header('Content-Disposition: attachment; filename="' . $streamname . '"');
if (strrchr($streamname, '.') == '.mp4') {
header('Content-Type: video/mp4');
} else {
header('Content-Type: video/x-flv');
}
header('Content-Length: ' . $fsize);
session_cache_limiter('nocache');
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre check=0');
header('Pragma: no-cache');
$file = fopen($streamname, 'rb');
print(fread($file, $fsize));
fclose($file);
exit;
} else {
header('Location: /url/');
}
?>
注意,$streamname 是从 JS 的 url 部分中提取的
<script type="text/javascript">
// <![CDATA[
window.onload = function () {
$f("player", "flowplayer-3.2.16.swf", {
plugins: {
secure: {
url: "flowplayer.securestreaming-3.2.8.swf",
timestampUrl: "sectimestamp.php"
}
},
clip: {
url: "trailer.flv",
urlResolvers: "secure",
scaling: "fit",
onStart: function (clip) {
document.getElementById("info").innerHTML = clip.baseUrl + "/" + clip.url;
}
}
});
};
// ]]>
</script>
如果有人试图从 Flash 播放器中直接提取源代码,并且当他们查看源代码时,他们只会看到文件名但域等通过 php 文件提供。