Home  >  Article  >  Backend Development  >  PHP anti-hotlink code example, PHP anti-theft example_PHP tutorial

PHP anti-hotlink code example, PHP anti-theft example_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:20:04876browse

PHP anti-hotlink code examples, PHP anti-theft examples

Anti-hotlinking is a very common web programming technique nowadays. This article uses an example to demonstrate the implementation method of PHP anti-hotlinking. Share it with everyone for your reference. The specific method is as follows:

The main function codes are as follows:

<&#63;php
/*
使用方法:将上述代码保存为dao4.php,
比如测试用的validatecode.rar在站点http://www.XXXX.com里面,
则用以下代码表示下载连接.
文件名&#63;site=1&file=文件 
例如以下URL:
http://www.XXXX.cn/dao4.php&#63;site=1&file=validatecode.rar 
*/
$ADMIN[defaulturl] = "http://www.XXXX.com/404.htm"; //盗链返回的地址
$okaysites = array(
  "http://www.XXXX.com/",
  "http://XXXX.com"
); //白名单
$ADMIN[url_1] = "http://www.XXXX.com/download/"; //下载地点1
$ADMIN[url_2] = ""; //下载地点2,以此类推
$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]");
}
&#63;>

I hope this article will be helpful to everyone learning PHP programming.

php code to set anti-hotlinking

Implementing this with PHP consumes more resources. It is recommended to start with the server and change the apache configuration
The following is the code for PHP implementation. xxx.mp3 is the actual address of your music file. When distributing to the outside world, only the PHP address and mp3 address are transmitted. Not public to the public
37664276ced7140a94ba6896618990fc

php code to set anti-hotlinking

It can be realized. You can search on the Internet for the method of outputting pictures through php binary stream. Since the picture output needs to go through php, you can use php to judge it first

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/869448.htmlTechArticlePHP anti-hotlink code examples, php anti-theft examples anti-hotlinking is a very common web programming technique at present. This article uses an example to demonstrate the implementation method of PHP anti-hotlinking. Share it with everyone...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn