I'm writing an image protection script to pass image arguments to it.
It should check whether the requester is my server or not.
Here's the problem :: I cant get the script to identify who's requesting
the image! I looked into other similar scripts (image protection & anti-leech)
they all use getenv("HTTP_REFERER"), which doesnt work in my case (results in an empty string)
My current setting (SERVER_NAME) always results in my own server name, which always shows the pic
other settings get the requester but even when I request the image from a page in my website
it shows the stolen pic!
any suggestions?!
Here's my code ::
<?php
/
PHP Image Protecter V1.5.060804 by MBH -> www.MBHbox.net
/
$myDomains=array("MBHBOXSERVER","mbhboxserver","mbhbox.net","localhost");
$stolenPic="http://www.mbhbox.net/images/stolen.gif";
$protectedDir="/SERVER/images/";
//$ref=$SERVER['HTTP_HOST'];//resolves website name
$ref=$SERVER['SERVER_NAME'];//results the name of the server machine
//$ref=gethostbyaddr('');//results the name of the server machine
//$ref=gethostbyaddr(getenv("REMOTE_ADDR"));//results the name of the requester
//$ref=getenv("HTTP_REFERER");
$VersioN="1.5.060804";
if ($version=="check") {
print Header("Location: http://www.mbhbox.net/cgi-bin/pip/lastVersion.php");
die('See <a href=http://www.mbhbox.net/cgi-bin/pip/lastVersion.txt>[url]http://www.mbhbox.net/cgi-bin/image/lastVersion.php[/url]</a>');
}
if ($img=="") die('no image defined');
if ($ext=="") die('no extension defined');
$isValid=false;
$name=$protectedDir.$img.".".$ext;
$fp = fopen($name, 'rb');
for ($i=0;$i<count($myDomains);$i++) {
if ($ref==$myDomains[$i]) {
$isValid=true;
}
}
if ($isValid==false) {
print Header("Location: $stolenPic");
die("<b>stolen picture!</b>");
}
header("Content-Type: image/$ext");
header("Content-Length: ".filesize($name));
fpassthru($fp);
exit();
?>