Search code examples
phpjavascripthotlinking

Check if a remote image is hotlink-protected


I would like to check if a remote image is hotlink-protected, or not.

  • If the image is not protected against hotlinking, I would like to display the image. (Don't worry, I will add a visible hyperlink to the source, and I will give the legitimate owner the possibility to remove the image.)
  • If the image is protected, I would do nothing.

Is it possible (with PHP and/or Javascript) to make the distinction between hotlink-protected images and 'hotlinkable' images?


Solution

  • Yes, you can definitely do this from PHP. When you want to hotlink the file, create an HTTP connection and set the Referer header in the request to your site. If you get a 200 response with the image data, it is not hotlink protected. If you get a 301 forwarding response it is hotlink protected.