在php框架入口文件头部添加如下内容:
//使用地址防止盗链
//允许的地址
$url=array(
'',
'',
''
);
if(isset($_SERVER['HTTP_REFERER'])&&!in_array($_SERVER['HTTP_REFERER'],$url)){
header('HTTP/1.1 403 Forbidden');
}
//使用域名防止盗链
//允许的域名
$url=array(
'',
''
);
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');
}
}
阅读(1409) | 评论(0) | 转发(0) |