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: |
Copy code |
<? Php 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: |
Copy code |
<? Php /** * @ Author seraphim * @ Copyright 2012 */ $ ADMIN = array ( 'Defaulturl '=> 'yun _ qi_img/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: |
Copy code |
<? Php $ ADMIN [defaulturl] = "http://www.111cn.net/404.htm"; // address returned by leeching $ Okaysites = array ("http://www.111cn.net/", "http://111cn.net"); // white list $ ADMIN [url_1] = "http://www.111cn.net/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.