zoukankan      html  css  js  c++  java
  • 绕过图片防盗链的方法_实测可用

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

    原文链接:http://justcoding.iteye.com/blog/1119238

  • 相关阅读:
    vim for python配置
    Python学习的一些好资料
    【Python开发实战】Python环境的配置
    【Python开发实战】Windows7+VirtualBox+Ubuntu环境配置
    linux下shapely的安装
    【python常用模块】os.path
    linux下gdal的python包的安装
    由二叉树的前序遍历和中序遍历,求其后序遍历
    ASCII码表
    C++标准库函数之排列函数
  • 原文地址:https://www.cnblogs.com/kt520/p/3659890.html
Copyright © 2011-2022 走看看