php破解防盗链技术
php破解防盗链技术
发送http请求
构造referer信息
在Http协议中,头信息里,有一个重要的选项: Referer
Referer: 代表网页的来源,即上一页的地址
具体方法http.class.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | // http请求类的接口 interface Proto { // 连接url function conn( $url ); //发送get查询 function get(); // 发送post查询 function post(); // 关闭连接 function close(); } class Http implements Proto { const CRLF = "\r\n" ; protected $errno = -1; protected $errstr = '' ; protected $response = '' ; protected $url = null; protected $version = 'HTTP/1.1' ; protected $fh = null; protected $line = array (); protected $header = array (); protected $body = array (); public function __construct( $url ) { $this ->conn( $url ); $this ->setHeader( 'Host: ' . $this ->url[ 'host' ]); } // 此方法负责写请求行 protected function setLine( $method ) { $this ->line[0] = $method . ' ' . $this ->url[ 'path' ] . '?' . $this ->url[ 'query' ] . ' ' . $this ->version; } // 此方法负责写头信息 public function setHeader( $headerline ) { $this ->header[] = $headerline ; } // 此方法负责写主体信息 protected function setBody( $body ) { $this ->body[] = http_build_query( $body ); } // 连接url public function conn( $url ) { $this ->url = parse_url ( $url ); // 判断端口 if (!isset( $this ->url[ 'port' ])) { $this ->url[ 'port' ] = 80; } // 判断query if (!isset( $this ->url[ 'query' ])) { $this ->url[ 'query' ] = '' ; } $this ->fh = fsockopen ( $this ->url[ 'host' ], $this ->url[ 'port' ], $this ->errno, $this ->errstr,3); } //构造get请求的数据 public function get() { $this ->setLine( 'GET' ); $this ->request(); return $this ->response; } // 构造post查询的数据 public function post( $body = array ()) { $this ->setLine( 'POST' ); // 设计content-type $this ->setHeader( 'Content-type: application/x-www-form-urlencoded' ); // 设计主体信息,比GET不一样的地方 $this ->setBody( $body ); // 计算content-length $this ->setHeader( 'Content-length: ' . strlen ( $this ->body[0])); $this ->request(); return $this ->response; } // 真正请求 public function request() { // 把请求行,头信息,实体信息 放在一个数组里,便于拼接 $req = array_merge ( $this ->line, $this ->header, array ( '' ), $this ->body, array ( '' )); //print_r($req); $req = implode(self::CRLF, $req ); //echo $req; exit; fwrite( $this ->fh, $req ); while (! feof ( $this ->fh)) { $this ->response .= fread ( $this ->fh,1024); } $this ->close(); // 关闭连接 } // 关闭连接 public function close() { fclose( $this ->fh); } } $http = new Http( 'http://localhost/apple.jpg' ); //本机服务器www目录下的apple.jpg图片 $http ->setHeader( 'Referer: http://localhost' ); //构造Referer信息 $res = $http ->get(); //print_r($res); file_put_contents ( './aa.png' , substr ( strstr ( $res , "\r\n\r\n" ),4)); |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战