php中图片防盗链如何绕过的方法
假设:
http://cdn.jbxue.com//uploads/2011/06/1309476244-elicium-rai-01-528x351.jpg
假设这是一张防盗链的图片,直接打开时无法显示真实图片(除chrome浏览器外)。
解决方法如下所示。
1、使用iframe的方法
<iframe id="imiframe" src="javascript:parent.sc" style="border:none; overflow: hidden;" scrolling="no" frameborder="0" onload="javascript:var x=document.getElementById('imiframe').contentWindow.document.images[0];this.width=x.width+10;this.height=x.height+10;"></iframe>
2、curl的方法
用法:
3、PHP header发送各种类型文件下载
文件名:showpic.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 ,原因在于:这些代码之前不要有任何内容输出的,包括空白,切记!
有了以上的代码,就可以这样显示图片了:
真是道高一尺,魔高一丈啊,php图片防盗链就这样没有守住防线,哈哈。
您可能感兴趣的文章:
PHP防盗链图片怎么破解?实例代码
PHP禁止图片盗链
php采集防图片盗链方法
php中图片防盗链如何绕过的方法
php破解apache,nginx,iis防盗链图片
PHP禁止图片文件的被盗链函数
php中curl破解图片防盗链
asp.net使用ashx实现图片防盗链的方法
PHP网站大流量与高并发的解决方法
php采集远程图片的思路与实现代码