您好,欢迎访问一九零五行业门户网

两种PHP防盗链方法

1.简单防盗链
代码如下:
$admin[defaulturl] = "http://jb51.net/404.htm";//盗链返回的地址 $okaysites = array("http://jb51.net/","http://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.软件下载的防盗链方法
代码如下:
//放置下载软件的根目录相对于当前脚本目录的相对目录 $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)) ?>
以上就是两种php防盗链方法的详细内容。
其它类似信息

推荐信息