943,923 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2228
  • PHP RSS
Dec 8th, 2006
0

hotlinking prevention detection

Expand Post »
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]
Similar Threads
Reputation Points: 32
Solved Threads: 41
Junior Poster
pzuurveen is offline Offline
196 posts
since Sep 2006
Dec 9th, 2006
0

Re: hotlinking prevention detection

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".

PHP Syntax (Toggle Plain Text)
  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..
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Dec 11th, 2006
0

Re: hotlinking prevention detection

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
PHP Syntax (Toggle Plain Text)
  1. echo "image = <img src={$this->imageUrl} />";
to get a visual feedback during development. This does get blocked.
Reputation Points: 32
Solved Threads: 41
Junior Poster
pzuurveen is offline Offline
196 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Problem in session using php5
Next Thread in PHP Forum Timeline: info required on authentication





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC