当前位置: 移动技术网 > IT编程>开发语言>PHP > php防盗链的常用方法小结

php防盗链的常用方法小结

2019年04月28日  | 移动技术网IT编程  | 我要评论

李映熹,美少女成长计划5.2版本,蒸刑

1.简单防盗链
复制代码 代码如下:

$admin[defaulturl] = "http://jb51.net/404.htm";//盗链返回的地址
$okaysites = array("http://jb51.net/","//www.jb51.net"); //白名单
$admin[url_1] = "http://jb51.net/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://jb51.net/temp/download里面,
则用以下代码表示下载连接.


code: [copy to clipboard]
文件名?site=1&file=文件

2.服务器防盗链
用到iis防盗链软件,可以搜下,网上有很多。s.jb51.net里面有的下

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

复制代码 代码如下:

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

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)){
?>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网