Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

checking image for hotlinking

i'm triyng to write something that will check if image is hotlinkable...
i've found some JavaScript solutions, but i want to write it in php...
is it possible?
and how?
0
svsvsv4
Asked:
svsvsv4
  • 4
  • 2
1 Solution
 
petoskey-001Commented:
Here is an excellent article on the topic.  PHP and Mod_Rewrite.  What I really like about this solution is that it not only stops people from viewing the image, it also redirects them to your website proper if they try viewing the image directly in their address bar.

http://www.alistapart.com/articles/hotlinking/
0
 
svsvsv4Author Commented:
no, i meant that i want to check if remote image is hotlinkable...
0
 
petoskey-001Commented:
So... you have a list of image url's and you want to find out which ones you can link to remotely?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
petoskey-001Commented:
Why not just try to load the image in your browser?  How many images to you have to link to?
0
 
svsvsv4Author Commented:
i'm trying to make a script that will check big list of images...
0
 
petoskey-001Commented:
I see, that's what I thought.  Well I'm going to sign off on this one then.  Hotlinking uses other people's bandwidth without their permission.  Even if you have some valid reason the solution could be used to steal bandwidth from lots of people.  I don't agree with the practice and won't be part of a solution that's posted so publicly.  Sorry.
0
 
Diablo84Commented:
I Concur.

However giving you the benefit of the doubt, as this may be used for a moral reason, such as testing if images on a server you are are in control of are correctly proteced, i will point you in the right direction.

There is no flawless method that comes to mind because some servers send an alternative file (such as a "hotlinking prohibited" image in place of the requested one) however for those that just deny you access to the file you can attempt to read it with file_get_contents or fsockopen. If they return true then the file is readible, if they return false then they could not connect to the file - so either it does not exist or it is hotlink protected.

eg.

if (@file_get_contents("http://somedomain.com/someimage.jpg")) echo "Image Found";
else echo "Could not connect to Image";

Some relevant manual links: http://www.php.net/manual/en/function.file-get-contents.php OR http://www.php.net/manual/en/function.fsockopen.php

And that is as much information as i intend to share on this one.

Please DO NOT leech other people bandwidth, if that is indeed the motive behind this script. Bandwidth costs people money and its a giant pain in ar... wallet if another site drains away your resources. The last site that leeched an image from my domain returned the next day to find out that i had replaced it on my server with a 2000*2000px transparent gif which needless to say rendered their page pretty useless.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now