chimage - image protection causing errors ... help please.

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   chimage - image protection causing errors ... help please.
cansics
CZ Newbie
cansics has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Feb 05, 2006
0.00 posts per day
Posts: 5
Points: 142
   
Hi there,

Yesterday my ISP disabled my site because they thought this script was causing problems with their server.

Here is the extract from my error.log ...

-----------------------------------------

[05-Feb-2006 17:01:33] PHP Warning: getimagesize(/home/bubworld/.foobar/trends.gif) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory in /home/bubworld/public_html/nuke/chimage.php on line 48
[05-Feb-2006 17:01:33] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/bubworld/public_html/nuke/chimage.php:48) in /home/bubworld/public_html/nuke/chimage.php on line 59

-----------------------------------------

Here's the script which serves up the images. The images live in a directory outside the webserver root so they cannot be accessed directly.

Sometimes, the images havent been fully created (they update every minute or so) - so they're incomplete when they're requested by this script.

[B]How can I check the images are complete before attempting to serve them and therefore prevent the errors ?[/B]

Thanks, Bub.

-----------------------------------------

<?
/*
CHImageGuard (PHP version) 1.01
*/

$imagedir = "/home/mysite/mystor/" ;

$validprefixes = array (
"www.bbc.co.uk") ;


// --- YOU NEED NOT MODIFY ANYTHING AFTER THIS LINE ---

function isreferrerokay ( $referrer, $validprefixes )
{
$validreferrer = 0 ;
$authreferrer = current( $validprefixes );
while ($authreferrer) {
if (eregi( "^https?://$authreferrer/", $referrer )) {
$validreferrer = 1 ;
break ;
}
$authreferrer = next( $validprefixes );
}
return $validreferrer ;
}

//----------------------- main program -----------------------

$image = $_GET['image'] ;
$referrer = getenv( "HTTP_REFERER" );

if (isset($_GET['image'])) {

if (empty($referrer) ||
isreferrerokay( $referrer, $validprefixes )) {

$imagepath = $imagedir . $image ;

$imageinfo = getimagesize( $imagepath );
if ($imageinfo[2] == 1) {
$imagetype = "gif" ;
}
elseif ($imageinfo[2] == 2) {
$imagetype = "jpeg" ;
}
elseif ($imageinfo[2] == 3) {
$imagetype = "png" ;
}
else {
header( "HTTP/1.0 404 Not Found" );
exit ;
}

header( "Content-type: image/$imagetype" );
@readfile( $imagepath );

}
else {

if (isset($email)) {
mail( $email, "Bandwidth Theft Alert",
"WARNING:\n\n$referrer\ntried to access\n$image\n",
"From: CHImageGuard <$email>" );
}
header( "HTTP/1.0 404 Not Found" );
}
}
else {
header( "Location: $homepage" );
}

?>



Back to top Reply with quote
#2   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,430
   
Try this one:


<?
/*
CHImageGuard (PHP version) 1.01
*/

$imagedir = "/home/mysite/mystor/";

$validprefixes = array("www.bbc.co.uk");


// --- YOU NEED NOT MODIFY ANYTHING AFTER THIS LINE ---

function isreferrerokay($referrer, $validprefixes) {
   $validreferrer = 0;
   $authreferrer = current($validprefixes);
   while ($authreferrer) {
      if (eregi("^https?://$authreferrer/", $referrer)) {
         $validreferrer = 1;
         break;
      }
      $authreferrer = next($validprefixes);
   }
   return $validreferrer;
}

//----------------------- main program -----------------------

$image = $_GET['image'];
$referrer = getenv("HTTP_REFERER");

if (isset($_GET['image'])) {
   if (empty($referrer) || isreferrerokay($referrer, $validprefixes)) {
      $imagepath = $imagedir.$image;
      $imageinfo = @getimagesize($imagepath);
      if ($imageinfo[2] == 1) {
         $imagetype = "gif" ;
      } elseif ($imageinfo[2] == 2) {
         $imagetype = "jpeg" ;
      } elseif ($imageinfo[2] == 3) {
         $imagetype = "png" ;
      } else {
         header("HTTP/1.0 404 Not Found");
         exit;
      }
      if (is_file($imagepath)) {
         header("Content-type: image/$imagetype");
         @readfile($imagepath);
            } else {
            header("Location: $homepage");
                  exit;
            }
   } else {
      if (isset($email)) {
         mail($email, "Bandwidth Theft Alert", "WARNING:\n\n$referrer\ntried to access\n$image\n", "From: CHImageGuard <$email>");
      }
      header("HTTP/1.0 404 Not Found");
            exit;
   }
} else {
      header("Location: $homepage");
            exit;
}

?>




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#3   re: chimage - image protection causing errors ... help pleas
cansics
CZ Newbie
cansics has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Feb 05, 2006
0.00 posts per day
Posts: 5
Points: 142
   
What's the difference ?



Back to top Reply with quote
#4   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,430
   
That one checks to make sure it is a file before serving it.


      if (is_file($imagepath)) {
            header("Content-type: image/$imagetype");
            @readfile($imagepath);
      } else {
            header("Location: $homepage");
            exit;
      }




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum