Misc Links
Forum Archive
News Archive
File DB
 

Ads
 

Advertisement
Age of Valor - Ultima Online Free Shard
AoS/SE/ML/Custom - advanced code, dedicated staff, peerless bosses, non overpowered customs + much much more
 

Latest Forum Topics
Possibly shutting down forum in near future
Posted by Red Squirrel
on Jan 21 2012, 5:19:43 pm

How to solve "ZoneMinder Console - Stopped"
Posted by Red Squirrel
on Jan 14 2012, 12:28:31 am

had fun on last day of 2011
Posted by rovingcowboy
on Jan 01 2012, 5:30:47 pm

Merry Christmas!
Posted by rovingcowboy
on Jan 01 2012, 5:11:32 pm

How to solve SMF directory not writable
Posted by Red Squirrel
on Oct 15 2011, 12:03:38 am

 

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






    spacer
    15223 Hits Pages: [1] [2] 121 Comments
    spacer


    Latest comments (newest first)
    Posted by ZenithalRavage on May 05th 2005 (14: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 huh.gif

    So if someone has similar problems and the host does not allow the GDFONTPATH command, this could be your solution wink.gif

    spacer
    Posted by ZenithalRavage on May 05th 2005 (15:28)
    QUOTE (Streety @ May 7 2005, 09:19 AM)
    Hey, that is getting better! smile.gif

    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.

    thanx, well I lightend the background a bit more, this is pretty much how I want it wink.gif
    sig's here don't allow hyperlinking an image that sucks but this is possible on almost every other site I'm on so there the image links to my site, pretty cool stuff cool.gif

    spacer
    Posted by Streety on May 05th 2005 (09:19)
    Hey, that is getting better! smile.gif

    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.

    spacer
    Posted by ZenithalRavage on May 05th 2005 (08:51)
    Sorry for posting again, but this imagestring isn't half bad, see what I baked in the oven:

    http://www.a-base.dds.nl/sig_rss/zr_sig_rss.php dancingbanada.gif

    spacer
    Posted by ZenithalRavage on May 05th 2005 (08:24)
    Hey I'm getting closer!

    I had to rearrange the code a bit behind imagestring but at least it's taking info from the feed now!

    http://www.a-base.dds.nl/sig_rss/rss_image_d.php
    http://www.a-base.dds.nl/sig_rss/rss_image_d.txt <-code

    woei!

    spacer
    View all comments
    Post comment

    RPGBids Your MMO MMORPG Auction Super Site

    Top Articles Latest Articles
    - What are .bin files for? (28297 reads)
    - Text searching in linux with grep (22872 reads)
    - SPFDisk (Special Fdisk) Partition Manager (17123 reads)
    - Creating your own content management system with php (16875 reads)
    - PSP User's Guide (16612 reads)
    - How to Use MDADM Linux Raid (14868 reads)
    - What is Cloud Computing? (14904 reads)
    - Dynamic Forum Signatures (version 2) (15271 reads)
    - Successfully Hacking your iPhone or iTouch (15978 reads)
    - Ultima Online Newbie Guide (16428 reads)
    corner image

    This site best viewed in a W3C standard browser at 800*600 or higher
    Site design by Red Squirrel | Contact
    © Copyright 2012 Ryan Auclair/IceTeks, All rights reserved