| | |
hotlinking prevention detection
![]() |
•
•
Join Date: Sep 2006
Posts: 16
Reputation:
Solved Threads: 1
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]
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]
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".
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..
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)
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Sep 2006
Posts: 16
Reputation:
Solved Threads: 1
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
to get a visual feedback during development. This does get blocked.
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)
echo "image = <img src={$this->imageUrl} />";
![]() |
Similar Threads
- Internet Explorer & Windows Explorer (desktop shortcuts) Won't Load! (Viruses, Spyware and other Nasties)
- knoppix or else (Getting Started and Choosing a Distro)
- Aurora help needed (Viruses, Spyware and other Nasties)
- about:blan has broken me down (Viruses, Spyware and other Nasties)
- Bridge.dll. Need help. (Windows NT / 2000 / XP)
- Desktop shortcuts won't load--PCk (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: Problem in session using php5
- Next Thread: info required on authentication
Views: 1885 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
access ajax apache api array arrays auto binary box buttons cakephp check checkbox class classes cms code cookies curl database date delete directory display download dropdown dropdownlist drupal dynamic echo email error file files form forms functions header href htaccess html image images include insert ip java javascript joomla jquery limit link list login loop mail menu mlm mod_rewrite multiple mysql order output parse password paypal pdf php problem query radio random redirect regex remote script search security select server session soap sort source sql string syntax table update upload url user validation validator variable video web website wordpress xml






