PHP anti-leech code instance and php anti-leech instance
Anti-leech is a common web programming technique. This article uses an example to demonstrate the PHP anti-leech implementation method. Share it with you for your reference. The specific method is as follows:
The main function code is as follows:
<? Php/* usage: Save the above Code as dao4.php, such as test validatecode.rar in the site http://www.XXXX.com, then use the following code to download the connection. File Name? Site = 1 & file = file such as the following URL: http://www.XXXX.cn/dao4.php? Siteapps1&file=validatecode.rar */$ ADMIN [defaulturl] = "http://www.XXXX.com/404.htm"; // address returned by leeching $ okaysites = array ("http://www.XXXX.com/", "http://XXXX.com "); // whitelist $ ADMIN [url_1] = "http://www.XXXX.com/download/"; // download location 1 $ ADMIN [url_2] = ""; // download location 2, similarly, $ 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 [defaulturl]") ;}} else {header ("Location: $ ADMIN [defaulturl]") ;}?>
I hope this article will help you learn PHP programming.
Php anti-leech code
This implementation using php consumes more resources. We recommend that you start with the server and change apache configuration.
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.
<? Php
If (strpos ($ _ SERVER ['HTTP _ referer'], 'qq. com ')! = FALSE ){
Header ('HTTP/1.1 404 Not Found ');
Exit;
}
Readfile('xxx.mp3 ');
?>
Php anti-leech code
You can search for the php binary stream output image on the Internet. Because the image output must go through php, you can use php to determine first.