侯体宗的博客
  • 首页
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

php实现的网络相册图片防盗链完美破解方法

php  /  管理员 发布于 7年前   469

本文实例讲述了php实现的网络相册图片防盗链完美破解方法。分享给大家供大家参考。具体如下:

网络相册图片防盗链破解程序 - PHP版 这个防盗链破解版可以完美破解当下比较流行的: 百度相册,网易相册,360我喜欢等网站图片. 还可以实现简单的图片防盗链. 因为这个类是先进行获取远程图片, 然后再把图片发送到客户端,所以,算是进行了两次流量的传送.因此,会浪费空间流量,接下来,会开发缓存功能,这样可以实现节约流量!

referer = $referer;      // parse the http link       $this->parseLink($link);       // begin to fetch the image       $stream = pfsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);       if (!$stream){        header("Content-Type: $this->contentType;");         echo $this->CurlGet($link);       }else{         fwrite($stream, $this->buildHeaders());         $this->body = "";         $img_size = get_headers($link,true);        while (!feof($stream)) {           $this->body .= fgets($stream, $img_size['Content-Length']);           //fwrite($jpg,fread($stream, $img_size['Content-Length']));        }         $content = explode("\r\n\r\n", $this->body, 2);         $this->body = $content[1];        fclose($stream);          // send 'ContentType' header for saving this file correctly      // 如果不发送CT,则在试图保存图片时,IE7 会发生错误 (800700de)         // Flock, Firefox 则没有这个问题,Opera 没有测试         header("Content-Type: $this->contentType;");         header("Cache-Control: max-age=315360000");        echo $this->body;//保存图片         //file_put_contents('hello.jpg', $this->body);       }    }     /**      * Compose HTTP request header      *      * @return string      */  private function buildHeaders()     {       $request = "$this->method $this->path HTTP/1.1\r\n";       $request .= "Host: $this->host\r\n";       $request .= "Accept-Encoding: gzip, deflate\r\n";      $request .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; zh-CN; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1\r\n";    $request .= "Content-Type: image/jpeg\r\n";       $request .= "Accept: */*\r\n";       $request .= "Keep-Alive: 300\r\n";       $request .= "Referer: $this->referer\r\n";       $request .= "Cache-Control: max-age=315360000\r\n";       $request .= "Connection: close\r\n\r\n";       return $request;     }     /**      * Strip initial header and filesize info      */     private function extractBody(&$body)     {         // The status of link       if(strpos($body, '200 OK') > 0) {         // strip header         $endpos = strpos($body, "\r\n\r\n");         $body = substr($body, $endpos + 4);         // strip filesize at nextline         $body = substr($body, strpos($body, "\r\n") + 2);       }         }     /**      * Extra the http url      *      * @param $link      */  private function parseLink($link)     {       $this->link     = $link;       $this->components  = parse_url($this->link);       $this->host     = $this->components['host'];       $this->path     = $this->components['path'];       if(empty($this->referer)){        $this->referer   = $this->components['scheme'] . '://' . $this->components['host'];       }elseif($this->referer == '1'){        $this->referer   = '';      }      $this->filename   = basename($this->path);       // extract the content type       $ext = substr(strrchr($this->path, '.'), 1);       if ($ext == 'jpg' or $ext == 'jpeg') {         $this->contentType = 'image/pjpeg';       }       elseif ($ext == 'gif') {         $this->contentType = 'image/gif';       }       elseif ($ext == 'png') {         $this->contentType = 'image/x-png';       }       elseif ($ext == 'bmp') {         $this->contentType = 'image/bmp';       }       else {         $this->contentType = 'application/octet-stream';       }     }     //抓取网页内容     function CurlGet($url){       $url = str_replace('&','&',$url);       $curl = curl_init();       curl_setopt($curl, CURLOPT_URL, $url);       curl_setopt($curl, CURLOPT_HEADER, false);       curl_setopt($curl, CURLOPT_REFERER,$url);       curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; SeaPort/1.2; Windows NT 5.1; SV1; InfoPath.2)");       curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');       curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie.txt');       curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);       curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);       $values = curl_exec($curl);       curl_close($curl);       return $values;     }   }   /**   * 取得根域名   *   * @author   lonely   * @create    2011-3-11   * @version  0.11   * @lastupdate lonely   * @package Sl  */class RootDomain{     private static $self;    private $domain=null;    private $host=null;    private $state_domain;    private $top_domain;    /**     * 取得域名分析实例     * Enter description here ...     */  public static function instace(){      if(!self::$self)        self::$self=new self();      return self::$self;    }    public function __construct(){      $this->state_domain=array(        'al','dz','af','ar','ae','aw','om','az','eg','et','ie','ee','ad','ao','ai','ag','at','au','mo','bb','pg','bs','pk','py','ps','bh','pa','br','by','bm','bg','mp','bj','be','is','pr','ba','pl','bo','bz','bw','bt','bf','bi','bv','kp','gq','dk','de','tl','tp','tg','dm','do','ru','ec','er','fr','fo','pf','gf','tf','va','ph','fj','fi','cv','fk','gm','cg','cd','co','cr','gg','gd','gl','ge','cu','gp','gu','gy','kz','ht','kr','nl','an','hm','hn','ki','dj','kg','gn','gw','ca','gh','ga','kh','cz','zw','cm','qa','ky','km','ci','kw','cc','hr','ke','ck','lv','ls','la','lb','lt','lr','ly','li','re','lu','rw','ro','mg','im','mv','mt','mw','my','ml','mk','mh','mq','yt','mu','mr','us','um','as','vi','mn','ms','bd','pe','fm','mm','md','ma','mc','mz','mx','nr','np','ni','ne','ng','nu','no','nf','na','za','aq','gs','eu','pw','pn','pt','jp','se','ch','sv','ws','yu','sl','sn','cy','sc','sa','cx','st','sh','kn','lc','sm','pm','vc','lk','sk','si','sj','sz','sd','sr','sb','so','tj','tw','th','tz','to','tc','tt','tn','tv','tr','tm','tk','wf','vu','gt','ve','bn','ug','ua','uy','uz','es','eh','gr','hk','sg','nc','nz','hu','sy','jm','am','ac','ye','iq','ir','il','it','in','id','uk','vg','io','jo','vn','zm','je','td','gi','cl','cf','cn','yr'    );      $this->top_domain=array('com','arpa','edu','gov','int','mil','net','org','biz','info','pro','name','museum','coop','aero','xxx','idv','me','mobi');      $this->url=$_SERVER['HTTP_HOST'];    }    /**     * 设置URL     * Enter description here ...     * @param string $url     */  public function setUrl($url=null){      $url=$url?$url:$this->url;      if(empty($url))return $this;      if(!preg_match("/^http:/is", $url))        $url="http://".$url;      $url=parse_url(strtolower($url));      $urlarr=explode(".", $url['host']);      $count=count($urlarr);      if ($count<=2){        $this->domain=$url['host'];      }else if ($count>2){        $last=array_pop($urlarr);        $last_1=array_pop($urlarr);        if(in_array($last, $this->top_domain)){          $this->domain=$last_1.'.'.$last;          $this->host=implode('.', $urlarr);        }else if (in_array($last, $this->state_domain)){          $last_2=array_pop($urlarr);          if(in_array($last_1, $this->top_domain)){$this->domain=$last_2.'.'.$last_1.'.'.$last;$this->host=implode('.', $urlarr);          }else{$this->host=implode('.', $urlarr).$last_2;$this->domain=$last_1.'.'.$last;          }        }      }      return $this;    }    /**     * 取得域名     * Enter description here ...     */  public function getDomain(){      return $this->domain;    }    /**     * 取得主机     * Enter description here ...     */  public function getHost(){      return $this->host;    }  }  $referer = array('xuehuwang.com','zangbala.cn','qianzhebaikou.net','sinaapp.com','163.com','sina.com.cn','weibo.com','abc.com');  // Get the url, maybe you should check the given url   if (isset($_GET['url']) and $_GET['url'] != '') {     //获取来路域名    $site = (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : '';  //匹配是否是一个图片链接    if(preg_match('/(http|https|ftp|rtsp|mms):(\/\/|\\\\){1}((\w)+[.]){1,}([a-zA-Z]|[0-9]{1,3})(\S*\/)((\S)+[.]{1}(gif|jpg|png|bmp))/i',$_GET['url'])){      if(!empty($site)){        $tempu = parse_url($site);        $host = $tempu['host'];        $root = new RootDomain();        $root->setUrl($site);        if(in_array($root->getDomain(),$referer)){          $img_referer = (isset($_GET['referer']) && !empty($_GET['referer']))? trim($_GET['referer']) : '';          new Frivoller($_GET['url'],$img_referer);         }      }else{        $img_referer = (isset($_GET['referer']) && !empty($_GET['referer']))? trim($_GET['referer']) : '';        new Frivoller($_GET['url'],$img_referer);       }    }  }   ?>

希望本文所述对大家的php程序设计有所帮助。

您可能感兴趣的文章:

  • 使用PHP破解防盗链图片的一个简单方法
  • 破解图片防盗链的代码(asp/php)测试通过
  • php 破解防盗链图片函数
  • php实现图片文件与下载文件防盗链的方法
  • php实现博客,论坛图片防盗链的方法
  • 使用php伪造referer的方法 利用referer防止图片盗链
  • php中突破基于HTTP_REFERER的防盗链措施(stream_context_create)
  • 详解php伪造Referer请求反盗链资源
  • Referer原理与图片防盗链实现方法详解


  • 上一条:
    什么是PEAR?什么是PECL?PHP中两个容易混淆的概念解释
    下一条:
    PHP根据图片色界在不同位置加水印的方法
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 用Time Warden监控PHP中的代码处理时间(0个评论)
    • 在PHP中使用array_pop + yield实现读取超大型目录功能示例(0个评论)
    • Property Hooks RFC在PHP 8.4中越来越接近现实(0个评论)
    • 近期文章
    • 在windows10中升级go版本至1.24后LiteIDE的Ctrl+左击无法跳转问题解决方案(0个评论)
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(95个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-11
    • 2017-12
    • 2018-01
    • 2018-02
    • 2018-03
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-09
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    • 2024-05
    • 2024-06
    • 2024-07
    • 2024-09
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客