Website leeching will consume a lot of the bandwidth of the leeching website, and the real click rate may be very small, seriously damaging the interests of the leeching website. This article describes how to implement anti-leech protection using PHP and its basic ideas.
Website leeching will consume a lot of the bandwidth of the leeching website, and the real click rate may be very small, seriously damaging the interests of the leeching website. This article describes how to implement anti-leech protection using PHP and its basic ideas.
Leeching refers to the content that service providers do not provide services themselves. They use technical means to bypass the end user interfaces (such as advertisements) of other interests ), provide the service content of other service providers directly to end users on their own websites to defraud end users of browsing and clicking rates. Beneficiaries do not provide resources or provide few resources, but real service providers do not receive any benefits. Preventing leeching is an important task for every website developer.
Anti-leech can reduce the load on website servers. Here we share a php anti-leech implementation method:
General download steps: search-> output search result list-> go to the software details page-> click the Download button-> open the download page-> click Download to start download
My method is to post on the download page.
First, define a $ key = sdkfjwojf32413 in the public file of the website, which is equivalent to a key.
Generate a random number on the download page: $ certcode = '000000' (each time a random number is generated)
Then, an md5 () encrypted string is generated using the above two variables and the software ID.
Then generate the true software: file. php? Id = 5 & codekey = ksf1_ofsdkfsf
The id here is the software number. You can find the software address $ codekey = md5 ($ id. $ certcode. $ key) from the database)
Then save the certcode to the session ,,
Get the codekey and id in the file. php parameter, get $ key from the public file, and then get $ certcode from the session.
Verify the codekey to see if it is correct. If it is incorrect, exit. Otherwise, perform the following operations:
1. Delete the session (it will be invalid if this address is opened again)
2. Read the software address from the database, then read the software content, and output (use the PHP file reading method to output the software content to be downloaded instead of directly downloading the address to him)
In this way, you must open your own download page, open the address from your download page to download, and each time it is different, because the generated random number is different
You cannot download it even if it is connected to you elsewhere.
Extended reading (Implementation ):
1. Simple anti-leech
$ ADMIN [defaulturl] = "http://www.vvschool.cn/404.htm"; // address returned by leeching $ okaysites = array ("http://www.vvschool.cn/", "http://www.siyizhu.com "); // whitelist $ ADMIN [url_1] = "http://www.vvschool.cn/temp/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]") ;}?>
Usage: Save the preceding code as dao4.php. For example, if validatecode.rar is used in my test, use the following code to download the connection.
File Name? Site = 1 & file = file
2. Server anti-leech
3. Anti-leech protection for software downloads
// Place the root directory of the downloaded software to the relative directory of the current Script directory $ fileRelPath = ".. /.. /software "; // The URL that can be connected with exceptions. Note: you do not need to enter your own domain name. It can be downloaded for sure. // Null String ("") $ excludeReferArr = array ("www.wreny.com", "wreny.com"); chdir ($ fileRelPath); $ fileRootPath = getcwd (). "http://www.jb51.net/"; $ filePath = $ HTTP_GET_VARS ["file"]; $ url = parse_url ($ _ SERVER ["HTTP_REFERER"]); if ($ url [host]! = $ _ SERVER ["HTTP_HOST"] &! In_array ($ referHost, $ excludeReferArr) {?>
In fact, there are also many anti-leeching methods. Here we only list one general idea as a reference:
(1) IIS anti-leeching, using ISAPI_Rewrite, can be used as a solution for anti-leeching in Windows;
(2) image anti-leeching and adding watermarks to images. Although leeching can achieve this goal, they are also promoting their websites.
The above is the basic idea and setting method of PHP anti-leech. I hope it will be helpful for you to learn.