保护flash播放器中的mp3文件路径


Protecting mp3 file path in flash player

我的网站上有一个用于播放mp3文件的flash播放器。但是,如果有人使用"viewsource"或firebug等任何浏览器工具,那么他们可以找到参数,然后整理出实际的mp3文件url。我在后台使用php。应该有办法隐藏这些参数,但却不知道如何隐藏?

有什么想法吗?

前言:如果你在网上展示它,你可以偷走它。

也就是说,你可以通过一个php脚本来屏蔽文件的URL,这个脚本可以做两件事:

1) 转换可以验证的加密GET参数,并且只能使用一次(将变量存储在数据库或日志中)。此代码将在播放器加载时创建,一旦开始缓冲,文件就不能再使用了。这样,参数就不能只是一个随机字符串(它必须是可解密的),用户也不能只使用相同的URL。

用户将收到的html页面中的php看起来像:

$key = 'My EnCyption Key';
$unique_string = "Generated at ".time().$_SERVER['REMOTE_ADDR']; //the time element changes the string each time and the IP address controls for multiple users simultaneously loading the same page
$tolken = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));

然后闪存播放器将被设置为使用mp3文件:

http://yoursite.com/mp3/file_fetcher.php?file_id=123&tolken=<?php echo $tolken;?>

文件file_fetcher.php会有这样的内容(显然这需要一些充实):

$fixed_string_part = "Generated at ";
$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($_GET['tolken']), MCRYPT_MODE_CBC, md5(md5($key))), "'0");
if (substr($decrypted,0,strlen($fixed_string_part))!=$fixed_string_part){
   die("Your tolken is invalid");
}
//check that the tolken hasn't been used before:
$check_query = mysql_query("select * from `mp3_tolken_log` where `tolken`='$decrypted';",[connection identifier]); //write this more cleanly
if (mysql_num_rows($query)){
    die("You've already used that tolken!");
} else {
   $log_it = mysql_query("insert into `mp3_tolken_log` (`tolken`,`dateadded`) VALUES ($decrypted,NOW())"); //make sure it's in there so it can't be used again
}
//now get the file if we haven't already died
$contents = file_get_contents([path/to/mp3/file/specified/by/id/$_GET['file_id']]);
header('Content-Type: audio/mpeg');
echo $contents;

2) 请检查引用站点是否是您自己的站点(而不是他们试图直接访问脚本)。类似于:

if (!isset($_SERVER['HTTP_REFERER'])){die("Restricted Access!");};
$_u=parse_url($_SERVER['HTTP_REFERER']);
$_u=preg_replace("/(www.)/i","",strtolower($_u['host']));
$_i=$_SERVER['HTTP_HOST'];
$_i=preg_replace("/(www.)/i","",strtolower($_i));
($_u == $_i) or die("Restricted Access!");

当然,这些信息可能是伪造的,但在它和单一访问通行证之间,你不必担心直接下载。也就是说,请记住,有一百万种方法可以从流中获取文件,但没有办法阻止这种情况。