目錄
php实现的网络相册图片防盗链完美破解方法
首頁 php教程 php手册 php实现的网络相册图片防盗链完美破解方法

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

Jun 13, 2016 am 08:59 AM
php 圖片 完美 實現 方法 破解

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

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

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

  ?

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

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

/**

* 网络相册图片防盗链破解程序 - PHP版

*

* 使用方法:

*

* http://yourdomain/url.php?url=http://hiphotos.baidu.com/verdana/pic/item/baidupicture.jpg&referer=

* 其中url是指需要破解的图片URL,而referer是为了兼容一些不需要设置来路域名才能显示的相册,例如360我喜欢网,必须设置来路为空才能正常浏览. 所以,此时应该设置referer为1

*

* @author 雪狐博客

* @version 1.0

* @since July 16, 2012

* @URL http://www.xuehuwang.com

*/

class Frivoller

{

/**

* HTTP 版本号 (1.0, 1.1) , 百度使用的是 version 1.1

*

* @var string

*/

protected $version;

/**

* 进行HTTP请求后响应的数据

*

* @var 字符串格式

*/

protected $body;

/**

* 需要获取的远程URL

*

* @var 字符串格式

*/

protected $link;

/**

* An array that containing any of the various components of the URL.

*

* @var array

*/

protected $components;

/**

* HTTP请求时HOST数据

*

* @var 字符串

*/

protected $host;

/**

* The path of required file.

* (e.g. '/verdana/abpic/item/mygirl.png')

*

* @var string

*/

protected $path;

/**

* The HTTP referer, extra it from original URL

*

* @var string

*/

protected $referer;

/**

* The HTTP method, 'GET' for default

*

* @var string

*/

protected $method = 'GET';

/**

* The HTTP port, 80 for default

*

* @var int

*/

protected $port = 80;

/**

* Timeout period on a stream

*

* @var int

*/

protected $timeout = 100;

/**

* The filename of image

*

* @var string

*/

protected $filename;

/**

* The ContentType of image file.

* image/jpeg, image/gif, image/png, image

*

* @var string

*/

protected $contentType;

/**

* Frivoller constructor

*

* @param string $link

*/

public function __construct($link,$referer='')

{

$this->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','v

a','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','m

e','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

$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程序设计有所帮助。

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1670
14
CakePHP 教程
1428
52
Laravel 教程
1329
25
PHP教程
1274
29
C# 教程
1256
24
PHP:網絡開發的關鍵語言 PHP:網絡開發的關鍵語言 Apr 13, 2025 am 12:08 AM

PHP是一種廣泛應用於服務器端的腳本語言,特別適合web開發。 1.PHP可以嵌入HTML,處理HTTP請求和響應,支持多種數據庫。 2.PHP用於生成動態網頁內容,處理表單數據,訪問數據庫等,具有強大的社區支持和開源資源。 3.PHP是解釋型語言,執行過程包括詞法分析、語法分析、編譯和執行。 4.PHP可以與MySQL結合用於用戶註冊系統等高級應用。 5.調試PHP時,可使用error_reporting()和var_dump()等函數。 6.優化PHP代碼可通過緩存機制、優化數據庫查詢和使用內置函數。 7

PHP與Python:了解差異 PHP與Python:了解差異 Apr 11, 2025 am 12:15 AM

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PHP和Python:比較兩種流行的編程語言 PHP和Python:比較兩種流行的編程語言 Apr 14, 2025 am 12:13 AM

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

PHP行動:現實世界中的示例和應用程序 PHP行動:現實世界中的示例和應用程序 Apr 14, 2025 am 12:19 AM

PHP在電子商務、內容管理系統和API開發中廣泛應用。 1)電子商務:用於購物車功能和支付處理。 2)內容管理系統:用於動態內容生成和用戶管理。 3)API開發:用於RESTfulAPI開發和API安全性。通過性能優化和最佳實踐,PHP應用的效率和可維護性得以提升。

PHP的持久相關性:它還活著嗎? PHP的持久相關性:它還活著嗎? Apr 14, 2025 am 12:12 AM

PHP仍然具有活力,其在現代編程領域中依然佔據重要地位。 1)PHP的簡單易學和強大社區支持使其在Web開發中廣泛應用;2)其靈活性和穩定性使其在處理Web表單、數據庫操作和文件處理等方面表現出色;3)PHP不斷進化和優化,適用於初學者和經驗豐富的開發者。

PHP和Python:解釋了不同的範例 PHP和Python:解釋了不同的範例 Apr 18, 2025 am 12:26 AM

PHP主要是過程式編程,但也支持面向對象編程(OOP);Python支持多種範式,包括OOP、函數式和過程式編程。 PHP適合web開發,Python適用於多種應用,如數據分析和機器學習。

PHP與其他語言:比較 PHP與其他語言:比較 Apr 13, 2025 am 12:19 AM

PHP適合web開發,特別是在快速開發和處理動態內容方面表現出色,但不擅長數據科學和企業級應用。與Python相比,PHP在web開發中更具優勢,但在數據科學領域不如Python;與Java相比,PHP在企業級應用中表現較差,但在web開發中更靈活;與JavaScript相比,PHP在後端開發中更簡潔,但在前端開發中不如JavaScript。

PHP和Python:代碼示例和比較 PHP和Python:代碼示例和比較 Apr 15, 2025 am 12:07 AM

PHP和Python各有優劣,選擇取決於項目需求和個人偏好。 1.PHP適合快速開發和維護大型Web應用。 2.Python在數據科學和機器學習領域佔據主導地位。

See all articles