绕过图片防盗链的方法

http://cdn.archdaily.net/wp-content/uploads/2011/06/1309476244-elicium-rai-01-528x351.jpg

 

假设这是一张防盗链的图片,直接打开时无法显示真实图片(除chrome浏览器外),而下面是两种破解的方法:

 

1.  使用iframe的方法

 

<script>window.sc="<img src='http://cdn.archdaily.net/wp-content/uploads/2011/06/1309476244-elicium-rai-01-528x351.jpg?"+Math.random()+"'>";</script>
<iframe id="imiframe" src="javascript:parent.sc" style="border:none; overflow: hidden;" scrolling="no" frameborder="0" οnlοad="javascript:var x=document.getElementById('imiframe').contentWindow.document.images[0];this.width=x.width+10;this.height=x.height+10;"></iframe>

 

2. curl的方法

 

用法:
http://your-domain-name/showpic.php?url=image_url

 

PHP header发送各种类型文件下载

 

showpic.php

 

<?php
$url = $_GET["url"];
//$url = str_replace("http:/","http://",$url); 
$dir = pathinfo($url);
$host = $dir['dirname'];
$refer = $host.'/';

$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_REFERER, $refer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//激活可修改页面,Activation can modify the page
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);

$ext = strtolower(substr(strrchr($img,'.'),1,10));
$types = array(
			'gif'=>'image/gif',
			'jpeg'=>'image/jpeg',
			'jpg'=>'image/jpeg',
			'jpe'=>'image/jpeg',
			'png'=>'image/png',
);
$type = $types[$ext] ? $types[$ext] : 'image/jpeg';
header("Content-type: ".$type);
echo $data; 

遇到PHP 提示错误Cannot modify header information headers already sent ,拜托,这些代码之前不要有任何的 内容输出,包括空白!

 

 

OK 你可以这样显示图片了:

 

 

<img src="http://your-domain-name/showpic.php?url=http://cdn.archdaily.net/wp-content/uploads/2011/06/1309476244-elicium-rai-01-528x351.jpg" /> 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值