Php anti-Leech code. The anti-Leech code we mentioned here only focuses on php solutions. of course, if you have server management permissions or htaccess file operations, do not use php anti-Leech protection. First, let's take a look at the anti-Leech code described here. it only focuses on php solutions. of course, if you have server management permissions or htaccess file operations, I should not use php anti-Leech protection.
Let's take a look at the simplest
The following is the code implemented by php. xxx.mp3 is the actual address of your music file. only the php address is transmitted during external communication. The mp3 address is not publicly available.
The code is as follows: |
|
If (strpos ($ _ SERVER ['http _ referer'], 'qq. com ')! = FALSE ){ Header ('http/1.1 404 Not Found '); Exit; } Readfile('xxx.mp3 '); ?> |
How to add a whitelist
The code is as follows: |
|
/** * @ Author seraphim * @ Copyright 2012 */ $ ADMIN = array ( 'Defaulturl '=> 'http: // www.xx.com/images/banner-header.gif', // address returned by leeching 'URL _ 1' => 'http: // www.xx.net/file ', 'URL _ 2' => 'http: // www.xx.net/file1 ', ); $ Okaysites = array ( 'Http: // box.baidu.com ', 'Http: // tieba.baidu.com/p/1493336008', // whitelist 'Http: // www.xx.com/1.html ', ); $ Reffer = $ _ SERVER ['http _ referer']; If ($ reffer ){ $ Yes = 0; While (list ($ domain, $ subarray) = each ($ okaysites )){ If (ereg ($ subarray, "$ reffer ")){ $ Yes = 1; } } $ Theu = 'URL _ '. $ _ GET ['site']; $ File = $ _ GET ['file']; If ($ ADMIN [$ theu] and $ yes = 1 ){ Header ("Location: $ ADMIN [$ theu]/$ file "); } Else { Header ("Location: $ ADMIN [defaurl URL]"); } } Else { Header ("Location: $ ADMIN [defaurl URL]"); } Print_r ($ _ SERVER ['http _ referer']); ?> |
Instance 3 [supports whitelist 2]
The code is as follows: |
|
$ ADMIN [defaulturl] = "http://www.bKjia. c0m/404.htm"; // address returned by leeching $ Okaysites = array ("http://www.bKjia. c0m/", "http: // bKjia. c0m"); // white list $ ADMIN [url_1] = "http://www.bKjia. c0m/download/"; // download location 1 $ ADMIN [url_2] = ""; // download location 2, and so on $ Reffer = $ HTTP_REFERER; If ($ reffer ){ $ Yes = 0; While (list ($ domain, $ subarray) = each ($ okaysites )){ If (ereg ($ subarray, "$ reffer ")){ $ Yes = 1; } } $ Theu = "url". "_". "$ site "; If ($ ADMIN [$ theu] AND $ yes = 1 ){ Header ("Location: $ ADMIN [$ theu]/$ file "); } Else { Header ("Location: $ ADMIN [defaurl URL]"); } } Else { Header ("Location: $ ADMIN [defaurl URL]"); } ?> |
There are still many ways to implement anti-Leech protection. This article only describes how to use php to implement anti-Leech protection. for example, some websites generate html, which is not very convenient. we can operate on iis, apache, and htaccess.
Bytes. Let's first look at the most...