FAO: Anyone who wants stats in their sig

Soldato
Joined
18 Oct 2002
Posts
10,711
Location
Castle Anthrax
Add the moment adding new users to my main sig script is quite a labour intensive process and due to the impending demise of the GamesNight Crew script I can see that there is going to be a fair bit of demand for this.

Please bear with me whilst I try to come up with a better way of managing things, in the meantime I have posted below a version of my script which can run independently of the database that my main script uses. Anyone who has webspace which supports php can modify the variables to suit their needs and upload it to their webspace.

Also if anyone has experience of developing a webpage which can allow users to modify data in a MySQL database in a secure manner (ie people shouldn't be able to tweak other people's sig) and wants to put something togther for me it would be much appreciated.

The red line highlights a change made at 8:47 on 14th Jan - If you have a copy of this script older than this then you will need to change the line as shown.

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/forumdisplay.php?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="";
   $PostText="WU";
   $TextRed=251;
   $TextGreen=251;
   $TextBlue=251; 
   $FontSize=9;
   $TextX=83;
   $TextY=36;
   $ImageURL="http://www.kaiowas.plus.com/images/legosig/LegoSig_05.png";
   $UpdatePeriod=3600; //Maximum frequency in seconds at which the script will poll Berkeley 

//Setup Variables For Webspace - Must be absolute paths
   $LocalFile="/files/home3/kaiowas/cmp/WUTotal.dat";
   $FontFile="/files/home3/kaiowas/cgi-bin/fonts/verdana.ttf"; 


[color=red]if(!FileMTime($LocalFile) or time()-FileMTime($LocalFile)>$UpdatePeriod)[/color]
{
 
   //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 . " " . $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");
    $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");
    $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);
   }
?>
 
Last edited:
as i dont have access to a php server i will have to wait for you to sort out one i can use

thanks a lot m8, much appreciated!

:)
 
Just a point here. You will need to set write access to the directory that holds the script temp files (with CHMOD 777) or set it via your ftp browser, and you will need to upload the requisite font to the webspace too.

BTW, I am also available if anyone wants wu counts in their siggy. I currently host about 20 of them on my server for various team members (myself included :p) with room for many many more.

If you're stuck, then send me an e-mail and I'll do what I can to help.
 
Got my webserver set back up with php and mysql on it :)

Tried using your php script kaiowas but i can't get it to work :(

Keep gwetting an error on line 75 .... Parse error: parse error, unexpected T_STRING in C:\FoxServ\www\setstatsimg.php on line 75

i'm a total n00b to php and i guess i'm going about this the wrong way..trying to install a script before i know who it works but i seem to learn better this way :)

sirgaz
 
hey,

I have webspace that supports php, but i've never used it before, and I don't have a clue how to use php. What do I do with the script? I know I have to obviously change some parts of the script (such as changing kaiowas's email addy to mine) but how do I get the script working? What do i have to do?
 
Originally posted by wasc
hey,

I have webspace that supports php, but i've never used it before, and I don't have a clue how to use php. What do I do with the script? I know I have to obviously change some parts of the script (such as changing kaiowas's email addy to mine) but how do I get the script working? What do i have to do?

Dunno anything about php either, but at a guess from what I have seen, you'd need to change the email, change the image location url, upload it to your site, then set permission on it as per taliesyn (so its executable probably) then link to it using
IMG tags (either on a web page or using vBBS ones here)
 
Right first of all the 2 sections containing the variables at the top need to be set according to your requirements, whilst setting up it is probably best that you leave the "Setup Variables For Sig" section alone.

In the "Setup Variables For Webspace" section you will need to set the two variables to suit your webspace.

$LocalFile - This is the path to a file which will be created by the code to store your current WU count. As taliesyn pointed out you may need to change the permissions on the directory containing this file so that the script will be able to write to it.
$FontFile - This is the path a a ttf (TrueType Font) file which you need to have uploaded to your webspace.

Then you will need to ftp the script to your webspace and set CHMOD 755 to make it executable.

Once you've got the basic script working (It's currently set up to replicate my sig) then you can start experimenting with the "Setup Variables For Sig" section to customise it to suit your requirements - hopefully these settings are self explanatory but let me know if you can't work out what any of them do.
 
Ok..think i've got all that done except the chmod bit..i've got my own webserver using apache, php and mysql..how/where do i set this chmod thing?

cheers

sirgaz
 
If you have CUTEFTP, you right click on the file on the webserver and select CHMOD. If you use WSFTP you right click on the file, select FTP commands and then CHMOD.

Most FTP programs are pretty similar.

The directory that holds the file pointed to by "$LocalFile" in Kaiowas' script will need to be writable. This file holds a local copy of your wucount from Berkeley to avoid hitting their server constantly and is updated every hour ($UpdatePeriod=3600).
 
Last edited:
Is it a windows or *nix server? Although I'm not an expert I'm pretty sure that CHMOD isn't relevant to windows servers. If it's a *nix server then you should be able to telnet into it and set CHMOD from the cmd line.
 
Originally posted by sirgaz
apache for windows...the penguin still scares me :D

sirgaz

I'm not 100% on this but I believe that if you are going to try and run it on windows you need to use the path names in the format:
Code:
   $LocalFile="C:/files/home3/kaiowas/cmp/WUTotal.dat";
   $FontFile="C:/files/home3/kaiowas/cgi-bin/fonts/verdana.ttf";
Note the forward slashes instead of backslashes.

As I said not 100% but worth a try. ;)
 
Nope..still getting an error..seems to be with this line

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

Fatal error: Call to undefined function: imagettfbbox() in C:\FoxServ\www\setstatsimg.php on line 75

any ideas??

cheers

sirgaz
 
Create a file called 'test.php' on your server containing the following:

Code:
<HTML>
<HEAD>
<TITLE>Test PHP Script</TITLE>
</HEAD>
<BODY>
<?PHP
phpinfo();
?>
</BODY>
</HTML>

Run it, and look for :

gd.jpg


Mine is located here for comparison.

If you can't see this or similar then as Tas says, you will have to install the GD library to get it to work.
 
Got the gd thing into php...easy now i know how :)

still getting errors but i'll leave it till later in the week when i get my server live again.

Cheers
for the help so far

sirgaz
 
Kaiowas, I'm not sure about this bit of your script:

Code:
  $UpdatePeriod=3600; //Maximum frequency in seconds at which the script will poll Berkeley
Code:
if(!FileMTime($LocalFile) or time()-FileMTime($LocalFile)+3600>$UpdatePeriod)
I'd expect this to go to Berkeley every time the script is accessed (since you're adding 3600 to a positive time difference, and then comparing it against 3600). A trial run with the script on my new webspace would have hit Berkeley every time (if I'd left that bit of code in).

Oh, and BTW, my local stats cache is alive and well (and very fast once it has the current stats - which are set to expire after 10 minutes). I'm happy to leave it set up like this for the rest of SETI 1 - as we'll probably have to redo a lot of this stuff for SETI 2 anyway. I'll put the rest of the site sometime tomorrow (dunno if it'll be done before the end of Round 10 - but I'll try).
 
Last edited:
Back
Top Bottom