Home  >  Article  >  php教程  >  使用PHP破解防盗链图片的一个简单方法

使用PHP破解防盗链图片的一个简单方法

WBOY
WBOYOriginal
2016-06-13 09:34:14878browse

有自己的主机一般都会设计"防盗链", 其实包括图片防盗链,和下载防盗链等,如:
1.使用.htaccess设置防盗链

复制代码 代码如下:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?jb51.net/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.jb51.net/image.gif [R,L]


2.nginx设置防盗链

复制代码 代码如下:

location ~* \.(gif|jpg|png|swf|flv)$ {
 valid_referers none blocked jb51.net;
 if ($invalid_referer) {
  rewrite ^/ http://jb51.net/234_s.gif;
  #return 404;
 }
}


但怎么破解防盗链呢? 一般的防盗链是判断来路是否为自己的域名, 我们可以使用 php 内置的 file_get_contents 方法来请求这个图片(当然别的后端语言也有类似的方法), 如:

复制代码 代码如下:

//getImg.php?url=目标图片连接
header('Content-type: image/jpeg');
echo file_get_contents(isset($_GET["url"])?$_GET["url"]:'http://static.jb51.net/images/v1/loading-16-16.gif');
?>


看例子:

1, 直接加载防盗链图片:(该站未授权的图片显示都是空白)

2, 通过php读取图片:

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