Solved

checking image for hotlinking

Posted on 2004-10-08
7
276 Views
Last Modified: 2008-02-01
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
Comment
Question by:svsvsv4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 7

Expert Comment

by:petoskey-001
ID: 12258589
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
 

Author Comment

by:svsvsv4
ID: 12259069
no, i meant that i want to check if remote image is hotlinkable...
0
 
LVL 7

Expert Comment

by:petoskey-001
ID: 12259083
So... you have a list of image url's and you want to find out which ones you can link to remotely?
0
Industry Leaders: 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!

 
LVL 7

Expert Comment

by:petoskey-001
ID: 12259100
Why not just try to load the image in your browser?  How many images to you have to link to?
0
 

Author Comment

by:svsvsv4
ID: 12259180
i'm trying to make a script that will check big list of images...
0
 
LVL 7

Expert Comment

by:petoskey-001
ID: 12259246
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
 
LVL 27

Accepted Solution

by:
Diablo84 earned 500 total points
ID: 12260348
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question