PHP to do a good job of anti-theft chain setting method

Source: Internet
Author: User
Tags md5 php file vars root directory

hotlinking refers to the service providers themselves do not provide services content, through technical means to bypass other beneficial end user interface (such as advertising), directly on their own website to provide end users with other service providers of service content, cheat end users Browse and click-through. Beneficiaries do not provide resources or provide scarce resources, while real service providers do not get any benefits. Doing a good job of preventing hotlinking is an important job for every website developer.

Do a good job anti-theft chain work to the Web server to reduce a lot of pressure, here we share a PHP anti-theft chain Implementation method:

General Download steps: Find-> Output Find results list-> Enter the software detail page-> Click the download button-> Open download page-> Click Download, start download

My approach is to do the same on the download page

First, define a $key=sdkfjwojf32413 in the public file of the Web site, which is equivalent to a key.

Generate a random number on the download page: $certcode = ' 84615354 ' (each time you open the generated is different)

Then generate a MD5 () cipher string with the ID of the above two variables and software

Then generate the real download address of the software: FILE.PHP?ID=5&CODEKEY=KSFJWOFSDKFSF

The ID here is the number of the software you can find from the database $codekey =md5 ($id. $certcode. $key)
and save the Certcode to the session,

The Codekey and IDs obtained in the file.php parameters are then obtained from the public file $key and then obtained from the session $certcode

To Codekey to verify, see whether correct, if not correct exit, otherwise do the following operation

1, delete session (again open this address is invalid)

2, read the software address from the database, and then read the software content, and output (PHP file reading method output to download the software content rather than directly to his address to download)

So if you want to download, you must open your own download page, from your download page to open the address to download, and the download address is different every time, because the generated random number is not the same

Other places even to your download address, also can not download.

Expand reading (Concrete implementation):

1. Simple anti-theft chain

 
 
  1. $ADMIN [Defaulturl] = "Http://www.vvschool.cn/404.htm" ;//hotlinking return address
  2. $okaysites  =  Array   ("http://www.vvschool.cn/","http://www.siyizhu.com");//Whitelist
  3. $ADMIN [Url_1] = "http://www.vvschool.cn/temp/download/" //Download location 1
  4. $ADMIN [url_2] = "" ; //Download location 2, and so on  
  5. $reffer  =  $HTTP _referer  ;
  6. if ($reffer) {
  7. $yes  = 0;
  8. while (List ($domain, $subarray) = each ($okaysites )) {  
  9. if (ereg($subarray,"$reffer")) {
  10. $yes  = 1;
  11. }
  12. }
  13. $theu  =  "url" . "_" . "$site"  ;
  14. if ($ADMIN[$theu] and $yes = = 1) {
  15. Header ("Location: $ADMIN [$theu]/$file");
  16. } else {
  17. Header ("Location: $ADMIN [Defaulturl]");
  18. }
  19. } else {
  20. Header ("Location: $ADMIN [Defaulturl]");
  21. }?>

How to: Save the above code as dao4.php, such as my test validatecode.rar in my Site http://vvschool.cn/temp/download, then use the following code to express the download connection.

File name? site=1&file= files

2. Server anti-theft Chain

3. Software downloads the anti-theft chain method

 
  
  
  1. //place the root directory of the download software relative to the current script directory  
  2. $fileRelPath  =  ;  
  3. //exceptions allow connected URLs, note: Their domain name does not need to be filled in, Set to be sure to download,  
  4. //  empty string ("") for direct input to Web site downloads  
  5. $EXCLUDEREFERARR  =  array ( ,   );  
  6. chdir ( $fileRelPath );  
  7. $fileRootPath  =  GETCWD ()  . ;  
  8. = $HTTP _get_vars [ ];  
  9. Li class= "alt" > = parse_url ( Span class= "VARs" >$_server [ ]);  
  10. if ( $url [host]! = $_server [ ]  && !in_array ( ,   $ Excludereferarr ) {   

In fact, there are many ways of hotlinking, here only a general idea as a reference: ⑴iis anti-hotlinking, using Isapi_rewrite, can be used as a solution to Windows hotlinking; ⑵ picture Anti-hotlinking, add watermark in the picture, although the hotlinking can achieve the goal, But they are also doing publicity for their website.

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.