|
Send spam to:
website@xeonlive.com
nick@xeonlive.com
georgiapeach1241@aol.com
How to make a dynamic forum signature
Make people wonder... By Red Squirrel
The code
The concept behind this is quite simple. First, you have separate images (preferably all the same physical size). These can be hosted anywhere, it does not need to be the same server, as long as they are not in the folder that you are forcing all files to run as php! Otherwise it will try to run a real image file as php and that does not work!
Then, the script simply goes through them and displays a different one each time!
The main image is actually code, and not image data. But it's renamed to .jpg or .gif instead of .php. There are mainly two parts to this and many ways to do it.
The first part is a way of shuffling the available sig images. The way I do it is to simply have a file with a number and raise that number every time the script is executed, and depending on what the number is, a sig is displayed. If you have 9 sig images, you just need to make sure that when the number reaches 9, it goes back to 1.
The second part of this code is to display the signature, this involves using a HTTP header and simply redirecting to the image et voila!
<?php
$images = 9; //number of images
//---- file management stuff ----
$numberfile = fopen("number.txt","r");
$number=fgets($numberfile,10);
fclose($numberfile);
$number=$number+1;
if($number>$images)$number=0;
$numberfile = fopen("number.txt","w");
fputs($numberfile,$number."\n");
fclose($numberfile);
header("Cache-Control: no-cache, must-revalidate, no-store"); //force browsers to not cache it
//display the right image depending on what the number is:
if($number==1)header("Location: http://www.yoursite.com/sigs/sigimage11a.jpg");
if($number==2)header("Location: http://www.yoursite.com/sigs/sigimage11b.jpg");
if($number==3)header("Location: http://www.yoursite.com/sigs/sigimage11c.jpg");
if($number==4)header("Location: http://www.yoursite.com/sigs/sigimage11d.jpg");
if($number==5)header("Location: http://www.yoursite.com/sigs/sigimage11e.jpg");
if($number==6)header("Location: http://www.yoursite.com/sigs/sigimage11f.jpg");
if($number==7)header("Location: http://www.yoursite.com/sigs/sigimage11g.jpg");
if($number==8)header("Location: http://www.yoursite.com/sigs/sigimage11h.jpg");
if($number==9)header("Location: http://www.yoursite.com/sigs/sigimage11i.jpg");
?>
|
If you simply named your images "image1","image2" etc you can even use this code which is much more efficient and compact:
<?php
$imagepath = "http://www.yoursite.com/sigs/sigimage";//where images are stored + filename w/o number
$sufix = ".jpg"; //sufix (usually the extension of the images)
$images = 9; //number of images
//---- file management stuff ----
$numberfile = fopen("number.txt","r");
$number=fgets($numberfile,10);
fclose($numberfile);
$number=$number+1;
if($number>$images)$number=0;
$numberfile = fopen("number.txt","w");
fputs($numberfile,$number."\n");
fclose($numberfile);
header("Cache-Control: no-cache, must-revalidate, no-store"); //force browsers to not cache it
header("Location: ".$imagepath.$number.$sufix); //display image
?>
|
As you can see, the code is quite simple, and there's many ways you can code it to randomize it. In mine, it simply rolls through all of them equaly, but more sophisticated code could be used to completly make the choosing random, however the point of this article is simply to show the basics and did not want to confuse you with more complex code.
Final notes
Here are a few things you should keep in mind:
Make sure that the folder that is keeping number.txt is chmodded to 777 as the script needs to write to that file! The file itself also has to be chmodded to 777.
If it does not work, it could be due to a parse error, to check for a parse error, simply put the path to the fake image in your address bar and it will run the php as text instead of an image and you will see the errors.
When you do link to the sig directly, because of the header, it will redirect your browser to the sig image it is suppost to display, so your address bar will actually display the path to the real image, so if you hit refresh, it will just display that and not run the script again.
Don't forget to actually create a number.txt file and put a number in it! That's assuming you are using the provided code.
Well this is it! I hope you've enjoyed it and that you will have fun making your friends wonder how you did it!
Later added notes: Not sure what I was thinking when I wrote this but the code above can be greatly simplified by using rand() instead of a file, check the forum thread for more info.
Red Squirrel
Owner/Webmaster IceTeks
| 37664 Hits |
Pages: [1] [2] |
121 Comments |
|
Latest comments (newest first) |
Posted by ZenithalRavage on May 05th 2005 (13:11)
phew, Imagettftext works now! I got a reply from my webhost and all I had to do was put ./ infront of the fontname, so instead of:
$font = "arial.ttf";
this:
$font = "./arial.ttf";
sheesh
So if someone has similar problems and the host does not allow the GDFONTPATH command, this could be your solution

|
Posted by ZenithalRavage on May 05th 2005 (14:28)
| QUOTE (Streety @ May 7 2005, 09:19 AM) | Hey, that is getting better! 
The text starts to fade out a bit as it goes across into the darker background. You could try creating a shadow as in the script from the php.net site. Might make it a bit more clear. |
|
|
|