Home >Backend Development >PHP Tutorial >php anti hotlink code

php anti hotlink code

WBOY
WBOYOriginal
2016-07-25 09:02:40883browse
php anti hotlink code原文地址: http://blog.qita.in
  1. /**
  2. * http://blog.qita.in
  3. */
  4. $ADMIN = array(
  5. 'defaulturl'=> 'http://blog.qita.in/images/banner-header.gif', //盗链返回的地址
  6. 'url_1' => 'http://blog.qita.in/file',
  7. 'url_2' => 'http://blog.qita.in/file1',
  8. );
  9. $okaysites = array(
  10. 'http://qita.in',
  11. 'http://blog.qita.in', //白名单
  12. 'http://blog.qita.in/1.html',
  13. );
  14. $reffer = $_SERVER['HTTP_REFERER'];
  15. if ($reffer) {
  16. $yes = 0;
  17. while (list($domain, $subarray) = each($okaysites)) {
  18. if (ereg($subarray, "$reffer")) {
  19. $yes = 1;
  20. }
  21. }
  22. $theu = 'url_' . $_GET['site'];
  23. $file = $_GET['file'];
  24. if ($ADMIN[$theu] and $yes == 1) {
  25. header("Location: $ADMIN[$theu]/$file");
  26. } else {
  27. header("Location: $ADMIN[defaulturl]");
  28. }
  29. } else {
  30. header("Location: $ADMIN[defaulturl]");
  31. }
  32. print_r($_SERVER['HTTP_REFERER']);
  33. ?>
复制代码


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