hotlinking prevention detection

Reply

Join Date: Sep 2006
Posts: 16
Reputation: pzuurveen is an unknown quantity at this point 
Solved Threads: 1
pzuurveen pzuurveen is offline Offline
Newbie Poster

hotlinking prevention detection

 
0
  #1
Dec 8th, 2006
Hi all

I'm writing a code to search image on google and parse the urls to a flash aplication. More and more I don't get the image but a picture that tells me not to hotlink. I want to detect this so I can look for another image. I've written a funtion that checks the heather so filter bad urls but it don't detect hotlink prevention. I don't want to load the image end check it size, it will slow down my code to much.
Anyone an idear?

my funtion:
[php]
function goodUrl($urlString)
{
if (strpos($urlString,'http://')===0)
{
$pf = curl_init($urlString);
curl_setopt($pf, CURLOPT_HEADER,True);
curl_setopt($pf, CURLOPT_FOLLOWLOCATION,False);
curl_setopt($pf, CURLOPT_RETURNTRANSFER,True);
curl_setopt($pf, CURLOPT_NOBODY, True);
curl_setopt($pf, CURLOPT_TIMEOUT,30);
$ret = curl_exec($pf);
$heathers = curl_getinfo($pf);
if ((empty($ret)) || ($heathers["http_code"] <> 200) || // bad connection
(strpos($heathers["content_type"],"image/") === false)) // not an image
{
curl_close($pf); // close cURL handler
return False;
}
else
{
curl_close($pf); // close cURL handler
return True;
}
}
else
{
return False;
}
}
[/php]
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,110
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 68
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: hotlinking prevention detection

 
0
  #2
Dec 9th, 2006
What you can do is try and get the filesize header from your CURL request you're making. If thats not available, then you will have to download the image data and get a filesize.

Once you have a filesize, you can compare it with the filesize of the image retrieved by the client to see if it matches.

In IE you can get the filesize of the image via javascript. fileSize is a property of the Image object.

Example: if you have an image with id="myimage".

  1. var image_size = document.getElementById('myimage').fileSize;

You can then send this back to your server in a HTTP Request.

I couldn't seem to find a corresponding property for the Image object in Firefox. So you may have to revert to having JavaScript retrieve the image headers for you on the client side (eg: xmlHTTPRequest), then send the Image Size to you via a seperate HTTP Request back to your PHP Server.

See: http://www.elf.org/essay/inline-image.html if you want to render the image inline as to keep the browser from making an extra http request for the image.

If you end up having to retrieve the whole image via CURL, then you might as well cache the image and serve up the local copy..
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 16
Reputation: pzuurveen is an unknown quantity at this point 
Solved Threads: 1
pzuurveen pzuurveen is offline Offline
Newbie Poster

Re: hotlinking prevention detection

 
0
  #3
Dec 11th, 2006
Thanks for the replay

I've discided to download the pictures. Turns out that downloading the image doesn't get blocked at all. :o
I put in
  1. echo "image = <img src={$this->imageUrl} />";
to get a visual feedback during development. This does get blocked.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 1885 | Replies: 2
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC