Home >Backend Development >PHP Tutorial >php防盗链解决方案?

php防盗链解决方案?

WBOY
WBOYOriginal
2016-06-06 20:52:011245browse

譬如我的站点是 xxx.com

资源站是 abc.com

我的资源站的东西只允许在xxx.com或者www.xxx.com上展示

据说可以使用白名单限制

请问用php如何解决?

谢谢诸位咯!!

补充一下..我是用提取码的方式来提取资源站的东西

http://xxx.com/link.php/code/

<?php $uri = $_SERVER["REQUEST_URI"];
 
preg_match("/link.php\/(.+)\//",$uri,$code);
 
$code = $code[1];

{
$url="http://www.abc.com/file/".$code;
} 

Header("Location:".$url);

?>

回复内容:

譬如我的站点是 xxx.com

资源站是 abc.com

我的资源站的东西只允许在xxx.com或者www.xxx.com上展示

据说可以使用白名单限制

请问用php如何解决?

谢谢诸位咯!!

补充一下..我是用提取码的方式来提取资源站的东西

http://xxx.com/link.php/code/

<?php $uri = $_SERVER["REQUEST_URI"];
 
preg_match("/link.php\/(.+)\//",$uri,$code);
 
$code = $code[1];

{
$url="http://www.abc.com/file/".$code;
} 

Header("Location:".$url);

?>

我能提供一个建议.用cookie和page refer

apache的 .htaccess 文件就可以做到,具体怎么做,嘿嘿,百度之

最前面加

$from = parse_url($_SERVER['HTTP_REFERER']);
if ($from['host']!='xxx.com' && $from['host']!='www.xxx.com') { die('你丫在盗链'); }

Apache下用Rewrite

如果是我来做防盗链的话:首先从服务器入手比较好,这里有篇文章绝对适合新手:
[Nginx配置图片防盗链,简单高效,快速,PHP程序不用改就能实现防盗链的功能,何乐而不为呢?]
http://www.qixing318.com/article/use-nginx-to-do-a-simple-anti-daolian-website.html
如还有问题,请在SF上给我留言^~^

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn