//判断防盗链域名
<?php
define('REFERER_URL', '');
function is_referer(){
//没有设置防盗链
if(REFERER_URL=='' || (empty($_SERVER['HTTP_REFERER']) && REFERER_ID==1)) return true;
//获取来路域名
$uriarr = parse_url($_SERVER['HTTP_REFERER']);
$host = $uriarr['host'];
$ymarr = explode("|",REFERER_URL);
if(in_array($host,$ymarr)){
return true;
}
return false;
}
使用方法
//防盗链
if(!is_referer(REFERER_URL)){
echo '非法访问,403~!';exit;
}