php防盗链的方法




php防盗链的方法
1.简单防盗链


  CODE: [Copy to clipboard]  


$ADMIN[defaulturl] = "http://siyizhu.com/404.htm";//盗链返回的地址
$okaysites = array("http://siyizhu.com/","http://www.siyizhu.com"); //白名单
$ADMIN[url_1] = "http://siyizhu.com/temp/download/";//下载地点1
$ADMIN[url_2] = "";//下载地点2,以此类推

$reffer = $HTTP_REFERER;
if($reffer) {
$yes = 0;
while(list($domain, $subarray) = each($okaysites)) {
if (ereg($subarray,"$reffer")) {
$yes = 1;
}
}
$theu = "url"."_"."$site";
if ($ADMIN[$theu] AND $yes == 1) {
header("Location: $ADMIN[$theu]/$file");
} else {
header("Location: $ADMIN[defaulturl]");
}
} else {
header("Location: $ADMIN[defaulturl]");
}

?> 



使用方法:将上述代码保存为dao4.php,
比如我测试用的validatecode.rar在我的站点http://siyizhu.com/temp/download里面,
则用以下代码表示下载连接.


  CODE: [Copy to clipboard]  
文件名?site=1&file=文件 



2.服务器防盗链
用到软件  IIS防盗链插件(UUIIS防盗链) 高级免费版
下在地址    http://code.netbei.com/old/old/2 ... softiisauthdemo.rar

3.软件下载的防盗链方法


  CODE: [Copy to clipboard]  
//放置下载软件的根目录相对于当前脚本目录的相对目录
$fileRelPath = "../../software";
//例外允许连接的网址,注意:自身域名不需要填入,设定为肯定可以下载,
// 空字符串("")表示直接输入网址下载的情况
$excludeReferArr = array("www.wreny.com", "wreny.com");

chdir($fileRelPath);
$fileRootPath = getcwd() ."/";

$filePath=$HTTP_GET_VARS["file"];

$url=parse_url($_SERVER["HTTP_REFERER"]);

if($url[host]!=$_SERVER["HTTP_HOST"] && !in_array($referHost, $excludeReferArr)){
?>
要下载软件请到...

exit;
}

$fileName = basename($filePath);
$fileAbsPath = $fileRootPath.$filePath;

if(empty($filePath)){
echo "未指定要下载的文件!";
exit;
}

//echo $fileAbsPath;
if(!file_exists($fileAbsPath)){
echo "对不起,此链接已经失效,请在论坛上向我们报告,谢谢!";
exit;
}

header("Cache-control: private"); // fix for IE
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($fileAbsPath));
header("Content-Disposition: attachment; filename=".$fileName);
$fp = fopen($fileAbsPath, 'r');
fpassthru($fp);
//fclose($fp);
?>



4.标记防盗链
第一页内随机的产生一个数(0-15)-》dechex()保存在session内

然后将URL使用此标记进性怂悖
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值