hotlink protection

后端 未结 2 581
星月不相逢
星月不相逢 2021-01-07 01:49

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

if ((strpos($_SERVER[\'HTTP_REFERER\'],\'www.domain.com\')!==0)) {
    $re         


        
2条回答
  •  暖寄归人
    2021-01-07 02:22

    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");
             }
       }
    

提交回复
热议问题