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" onload="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
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" />