2012-02-08 57 views
1

我在我的網站上播放MP3文件的Flash播放器。但如果有人使用「viewsource」或任何瀏覽器工具(如螢火蟲),那麼他們可以找到參數,然後整理出實際的mp3文件url.I在我的後端使用php。應該有一些隱藏這些參數,但不知道如何?保護Flash播放器中的MP3文件路徑

任何想法?

+1

Sidenote,但即使您在Flash文件中對URL進行了硬編碼,人們仍然可以使用Fiddler等功能非常輕鬆地截取(並保存)MP3的單獨請求。 – 2012-02-08 02:45:24

回答

4

前言:如果你在網上顯示它,你可以竊取它。期。

這就是說,你可以將其通過一個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)))); 

,然後再Flash播放器將被設置爲使用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!"); 

當然這些信息可以僞造,但它之間和單通行證,你不應該擔心直接下載。也就是說,請記住,有一百萬種方法可以從流中獲取文件,並且無法阻止該文件。