PHP code for anti hotlinking

前端 未结 6 1160
深忆病人
深忆病人 2020-12-03 09:26

In our sites we are doing a image protection section. So as a part of image protection we need provide antihotlinking for images.In our site we are showing the image using a

6条回答
  •  星月不相逢
    2020-12-03 09:47

    in image_file.php use http_referer for this.

    $ref = isset($_SERVER['HTTP_REFERER'])? $_SERVER['HTTP_REFERER']: "";
    if ($ref != "" && strpos($ref,'http://www.yourdomain.com/')===0)
    {
       //the request for this image is coming from some other domain, so take appropriate action
    }
    else
    {
      //do whatever logic you are currently using to show the images
    }
    

    Find a full-blown solution here: http://safalra.com/programming/php/prevent-hotlinking/

提交回复
热议问题