热链接保护 [英] hotlink protection

查看:111
本文介绍了热链接保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了这个简单的代码,以防止从我的php下载文件中链接我的文件:

i made this simple code to prevent hotlinking my files from my php download file :

if ((strpos($_SERVER['HTTP_REFERER'],'www.domain.com')!==0)) {
    $redirect='index.php';
    header("Location: $redirect");
    exit;
}

它不起作用,即使我单击wbesite内的链接,它也始终将我重定向到index.php. 我试图将域更改为许多类型,如:

it's not working , it always redirect me to index.php even if i clicked the link inside my wbesite. i tried to change the domain to many types like :

http://www.domain.com
www.domain.com
域. com

http://www.domain.com
www.domain.com
domain.com
domain

但仍然是相同的问题

推荐答案

我找到了解决方案,我只是使用strposHTTP_REFERERHTTP_HOST之间进行了比较,如果它们匹配意味着没有热链接.代码:

i found the solution, i just made a compare between HTTP_REFERER and the HTTP_HOST using strpos, if they match that mean there is no hotlinking. the code :


if($_SERVER['HTTP_REFERER'])
   {
      if(!strpos($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))
         {
            $redirect='index.php'; 
            header("Location: $redirect");
         }
   }

这篇关于热链接保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆