//使用地址防止盗链
//允许的地址
$url=array(
'http://www.baidu.com/index.php',
'http://www.google.com/index.html',
'http://10.156.19.26:802/php/index.html'
);
if(isset($_SERVER['HTTP_REFERER'])&&!in_array($_SERVER['HTTP_REFERER'],$url)){
header('HTTP/1.1 403 Forbidden');
}
//使用域名防止盗链
//允许的域名
$url=array(
'www.baidu.com',
'www.google.com'
);
if(isset($_SERVER['HTTP_REFERER'])){
$urlInfo=parse_url($_SERVER['HTTP_REFERER']);
if(!in_array($urlInfo['host'],$url)){
header('HTTP/1.1 403 Forbidden');
}
}
//使用跳转链接使用协议防止盗链
//允许协议
$scheme=array(
'http',
'https'
);
if(isset($_SERVER['HTTP_REFERER'])){
$urlInfo=parse_url($_SERVER['HTTP_REFERER']);
if(!in_array($urlInfo['scheme'],$url)){
header('HTTP/1.1 403 Forbidden');
}
}
//使用跳转链接端口过滤防止盗链
//允许端口
$port=array(
80,
8080
);
if(isset($_SERVER['HTTP_REFERER'])){
$urlInfo=parse_url($_SERVER['HTTP_REFERER']);
if(!in_array($urlInfo['port'],$port)){
header('HTTP/1.1 403 Forbidden');
}
}