I'm on my knees begging (PHP stats related)

would you be so kind as to paste the php code pls, I understand the basics, but would like to see how you have done it,

If there was a way to get the number automatically.. like lots of other sites seem to then there would be no need for the input file...


Valor.
 
Originally posted by Valor
would you be so kind as to paste the php code pls, I understand the basics, but would like to see how you have done it,

If there was a way to get the number automatically.. like lots of other sites seem to then there would be no need for the input file...


Valor.

Code:
<?php

//Code for overlaying SETI stats over a JPEG or PNG image
//By Phil Cutler (kaiowas) of Team OcUK Oct 2002
//Visit the OcUK team forum: [url]http://forums.overclockers.co.uk/fo...p?s=&forumid=39[/url]
//Uses a local file to cache the users total and reduce bandwidth hit on Berkeley

//Setup Variables For Sig
   $UserEmail="[email protected]";
   $PreText="Team OcUK - Get WU's Or Die Tryin'";
   $PostText="WU's owned";
   $TextRed=251;
   $TextGreen=251;
   $TextBlue=251; 
   $FontSize=12;
   $TextX=350;
   $TextY=12;
   $ImageURL="http://www.digital-designs.biz/seti/truz/truz.jpg";
   $UpdatePeriod=900; //Maximum frequency in seconds at which the script will poll Berkeley 

//Setup Variables For Webspace - Must be absolute paths
   $LocalFile="/home/www/digitalth/seti/truz/WUTotal.dat";
   $FontFile="/home/www/digitalth/seti/fonts/disco___.ttf"; 


if(!FileMTime($LocalFile) or time()-FileMTime($LocalFile)>$UpdatePeriod)
{
 
   //Get Total Number Of WUs from personal stats page at Berkeley
      $fp =@fopen ("http://setiathome.ssl.berkeley.edu/fcgi-bin/fcgi?email=" . $UserEmail . "&cmd=user_stats_new", "r");
        if ($fp)
        {
         while (!feof($fp))
         {
          $WebPage.=fgets($fp,200);
         }

         if (strpos($WebPage,"No user with that name was found")==0)
         {
          $TotalStart=strpos($WebPage,"Results Received");
          $StartPos=strpos($WebPage,"<td>",$TotalStart)+4;
          $EndPos=strpos($WebPage,"</td>",$StartPos);
           $WUs=ltrim(rtrim(substr($WebPage,$StartPos,$EndPos
-$StartPos)));
         }
         else
         { 
          $WUs="User not found."; 
         }
        }
      fclose($fp);

   //Update Local File With Total
   $Output = fopen ($LocalFile, "a"); 
   ftruncate ($Output, 0);
   fseek($Output,0);
   fwrite($Output, $WUs);
   fclose($Output);
}
else
{

   //Read Total from Local File
      $Local=@fopen ($LocalFile, "r");
      $WUs=fgets($Local,200);
      fclose($Local);
}


//Build Text String
    $Text=$PreText . "\r\n" . $WUs . " " . $PostText;

//Create Image
   $size = ImageTTFBbox ($FontSize, 0, $FontFile , $Text);

   $im_x=abs($size[4]-$size[0]);
   $im_y=abs($size[5]-$size[1]);

   if (substr($ImageURL,strlen($ImageURL)-3,3)=="jpg")
   {
    //Create a Sig image based on a JPEG
    Header("Content-type: image/jpeg");
    Header("Expires: " . gmdate("D, d M Y H:i:s", time() + 900) . " GMT");
    $im_size = GetImageSize ($ImageURL); 
    $imageWidth = $im_size[0];
    $imageHeight = $im_size[1];
    $im = ImageCreateFromJPEG($ImageURL); 
    $text_color = imagecolorclosest ($im, $TextRed, $TextGreen, $TextBlue);
    if ($TextX+$im_x>$imageWidth){$TextX=$imageWidth-$im_x-2;}
    if ($TextY>$imageHeight){$TextY=$imageHeight-2;}
    imagettftext ($im, $FontSize, 0, $TextX, $TextY, $text_color, $FontFile, $Text);
    ImageJpeg ($im);
    ImageDestroy ($im);
   }
   elseif (substr($ImageURL,strlen($ImageURL)-3,3)=="png")
   {
    //Create a Sig image based on a PNG
    Header("Content-type: image/png");
    Header("Expires: " . gmdate("D, d M Y H:i:s", time() + 900) . " GMT");
    $im_size = GetImageSize ($ImageURL); 
    $imageWidth = $im_size[0];
    $imageHeight = $im_size[1];
    $im = ImageCreateFromPNG($ImageURL); 
    $text_color = imagecolorclosest ($im, $TextRed, $TextGreen, $TextBlue);
    if ($TextX+$im_x>$imageWidth){$TextX=$imageWidth-$im_x-2;}
    if ($TextY>$imageHeight){$TextY=$imageHeight-2;}
    imagettftext ($im, $FontSize, 0, $TextX, $TextY, $text_color, $FontFile, $Text);
    ImagePNG ($im);
    ImageDestroy ($im);
   }
?>

Remember this code belongs to kaiowas sp please leave his copyright at the top of the php page. :)

EDIT: script updated, Mark G, please check i added the bit u said correctly, thanks.
 
Last edited:
Originally posted by TrUz
<SNIP>

Remember this code belongs to kaiowas sp please leave his copyright at the top of the php page. :)

You're polling Berkeley for your results every 60 seconds :confused: :eek:

Seems a bit often to me. If you're doing that, then there's very little point in caching your wu count in a file imho.

All my db scripts update every 15 mins, and I feel guilty because of that :p
 
TrUz, please can you edit the PHP script to correct that. I wouldn't want people using your script verbatim and not noticing this.

Usually, updating once an hour is OK, unless you return lots of results, but once every fifteen minutes is OK.

And another little tip:

After the lines
Code:
Header("Content-type: image/jpeg");
and
Code:
Header("Content-type: image/png");
add the line
Code:
Header("Expires: " . gmdate("D, d M Y H:i:s", time() + 900) . " GMT");
This cuts your bandwidth usage by about 50%.
 
Originally posted by Valor
so I should change mine to something a little longer?

Valor.

Absolutely, and also implement the change suggested by Mark G. If you do both, not only will your own bandwidth use be significantly cut, but so will Berkeley's.
 
TrUz, can I make a small suggestion about your initial script post?

Because of the colouration of the OcUK Forums the PHP code is very difficult to read in the post. If you change the PHP & /PHP tags to QUOTE & /QUOTE it makes it much easier to read :)
 
Back
Top Bottom