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

WBOY
Release: 2016-07-13 10:20:04
Original
851 people have browsed it

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;>

Copy after login

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
if(strpos($_SERVER['HTTP_REFERER'], 'qq.com') !== FALSE) {
header('HTTP/1.1 404 Not Found' );
exit;
}
readfile('xxx.mp3');
?>

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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!