Solved

checking image for hotlinking

Posted on 2004-10-08
7
273 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

785 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