Php anti-Leech code _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags ereg
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...

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.