Php provides a perfect solution to crack anti-Leech Protection for Network album images

Source: Internet
Author: User
This article mainly introduces php's perfect anti-Leech solution for network album images. it can capture anti-Leech network album images, which is of great practical value, for more information about how to use php to crack the anti-leeching of network album images, see the example in this article. Share it with you for your reference. The details are as follows:

Network album image anti-Leech cracking program-PHP version this anti-Leech cracking version can perfectly crack the popular: Baidu album, NetEase album, 360 I like to wait for website images. you can also implement simple image anti-Leech protection. because this class first obtains remote images and then sends the images to the client, two traffic transfers are performed. therefore, it will waste space traffic. Next, we will develop the cache function to save traffic!

<? Php/*** anti-Leech cracking program for network album images-PHP ** usage :** http://yourdomain/url.php?url=http://hiphotos.baidu.com/verdana/pic/item/baidupicture.jpg&referer= * The url indicates the URL of the image to be cracked, and the referer indicates the album to be compatible with some photos that do not need to be set as a domain name to be displayed. for example, 360 I like the Internet, you must set the access path to be empty for normal browsing. therefore, set referer to 1 ** @ author Xuehu blog * @ version 1.0 * @ since July 16,201 2 * @ URL. http://www.xuehuwang.com */Class Frivoller {/*** HTTP version (1.0, 1.1), Baidu uses version 1.1 *** @ var string */protected $ version; /*** response data after an HTTP request ** @ var string format */protected $ body; /*** remote URL to be obtained ** @ var string format */protected $ link;/*** An array that containing any of the varous components of the URL. ** @ var array */protected $ components;/*** HOST data during HTTP request ** @ var string */protected $ host;/*** The path of re Quired 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 fe Tch 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", $ this-> body, 2 ); $ this-> body = $ content [1]; fclose ($ stream); // send 'contenttype' header for saving this file correctly // If CT is not sent, when trying to save the image, IE7 will encounter an error (800700de) // Flock, Firefox will not have this problem, and Opera does not test header ("Content-Type: $ this-> co NtentType; "); header (" Cache-Control: max-age = 315360000 "); echo $ this-> body; // save the image // 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"; return $ request;}/*** Strip initial header and filesize info */p Rivate function extractBody (& $ body) {// The status of link if (strpos ($ body, '2014, 200 OK ')> 0) {// strip header $ endpos = strpos ($ body, "\ 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 ($ cur L, CURLOPT_FOLLOWLOCATION, 0); $ values = curl_exec ($ curl); curl_close ($ curl); return $ values ;}} /*** get the root domain ** @ 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;/*** retrieve domain name analysis instance * Enter description here... */public static function in Stace () {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 ', 'M', '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', 'F', 'fo', 'pf ', 'GF', 'tf', 'VA ', 'Ph', 'fj ', 'Fi ', 'CV ', 'fk', 'G', '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 ', 'Lil', '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', 'ffm ', 'mm', 'MS', 'ma ', 'mz', 'mz', 'MX ', 'nr', 'NP ', 'ni', 'ne', 'NG ', 'Nu', 'no ', 'NF ', 'A', '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', 'S1', 'sz ', 'SD', 'sr', 'sb', 'so', 'TJ ', 'tw', 'th ', 'tz ', 'to', 'TC', 'TT', 'tn ',' TV ', 'tr', 'TT', '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 ', 'ymr '); $ 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'];} /*** set URL * Enter description here... * @ param string $ url */pu Blic 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, $ t His-> 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;}/*** retrieve domain name * Enter description here... */public function getDomain () {return $ this-> domain;}/*** obtain the host * Enter descripti On here... */public function getHost () {return $ this-> host ;}}$ referer = array ('xuehuwang. com ', 'zangbala. cn ', 'qianzhew.kou.. net ', 'sinaapp. com ', '2017. com ', 'sina .com.cn', 'Weibo. com ', 'ABC. com '); // Get the url, maybe you shoshould check the given url if (isset ($ _ GET ['URL']) and $ _ GET ['URL']! = '') {// Obtain the origin domain name $ site = (isset ($ _ SERVER ['http _ referer']) &! Empty ($ _ SERVER ['http _ referer'])? $ _ SERVER ['http _ referer']: ''; // match whether it is an image link 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) ;}}}?>

I hope this article will help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.