php实现的文件下载程序中,一定要做好防盗链,尤其是防迅雷盗链下载。
网上已有的apache 防盗链的多种方法,不能完全防止迅雷的,迅雷可以完全模拟http行为,这点真让人头疼。
例子,php 防盗链来解决这个问题。
 
复制代码 代码示例:
<?   
$site="plcxue.com/docs";   
$http_reffer=$_SERVER['HTTP_REFERER'];   
if(strstr($http_reffer,$site)==null)   
{   
    exit("本站仿盗链,请到www.plcxue.com上下载!");   
}   
  
$softlinks="uploadfiles/200805/logo.rar";   
$clientfilename="网站LOGO";   
$fieltype=explode(".", $softlinks);   
$fieltype=$fieltype[count($fieltype)-1];   
if(fopen($softlinks,"r"))    
{   
    $clientfilename=$clientfilename.".".$fieltype;    
  
    header("Pragma: public");   
    header("Expires: 0");   
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");    
    header("Content-Type: application/octet-stream");   
    header( "Content-Disposition: attachment; filename="$clientfilename"");   
    header( "Content-Description: File Transfert");   
  
    @readfile($softlinks);   
}   
else  
{   
    echo("对不起~~文件出错!请联系客服!");   
}      
?> 
测试结果:
可以使用迅雷下载,但是不能使用迅雷盗链。
若发现迅雷仍然可以模拟http头下载,可以考虑更改http头,拦截盗链。