1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Guide: Random Image Signature

Discussion in 'All other topics' started by Vicious88, Jul 16, 2009.

  1. Vicious88

    Vicious88 Regular member

    Joined:
    Jan 25, 2007
    Messages:
    274
    Likes Received:
    0
    Trophy Points:
    26
    Note: Before continuing, please be aware that if you are going to use this signature method, you should ensure that any and all possible signature images fall within size limits set forth by the forums.

    Here at afterdawn that's 200x500 with a maximum file size of 50KB.

    ...

    Have you ever had a hard time deciding which signature to use? Perhaps you have a few that you're proud of and can't choose just one? Odds are you'd benefit from a random image signature.

    The way it works is simple:

    Your signature field contains a simple one-line HTML or BBCode that points towards a PHP File that you have hosted somewhere in a directory along with a bunch of signatures. Whenever someone views one of your posts, their computer will reach out to that PHP form, and it will randomly insert on of your signatures.

    There are many practicle applications for this, including having "Talking" signatures, like my own. Fortune Cookie sigs, and other fun little images.

    If you're interested in doing this, here's a list of what you'll need:
    ~Someplace online where you can host your files -- image hosting sites won't work, but any basic Free Webhosting package will do.
    ~Some images you want to use as signatures (make sure they are fall within forum rules!).
    ~The ability to copy and paste.

    Step by step:

    Step 1 - Making the Script.
    You're going to need to open up Notepad (Start>Run>"Notepad" [press Enter]), and copy the following code into it:
    Code:
    <?php 
    /* 
    */// Make this the relative path to the images, like "../img" or "random/images/". 
    // If the images are in the same directory, leave it blank. 
    $folder = ''; 
    
    // Space seperated list of extensions, you probably won't have to change this. 
    $exts = 'jpg jpeg png gif'; 
    
    $files = array(); $i = -1; // Initialize some variables 
    if ('' == $folder) $folder = './'; 
    
    $handle = opendir($folder); 
    $exts = explode(' ', $exts); 
    while (false !== ($file = readdir($handle))) { 
    foreach($exts as $ext) { // for each extension check the extension 
    if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive 
    $files[] = $file; // it's good 
    ++$i; 
    } 
    } 
    } 
    closedir($handle); // We're not using it anymore 
    mt_srand((double)microtime()*1000000); // seed for PHP < 4.2 
    $rand = mt_rand(0, $i); // $i was incremented as we went along 
    
    header('Location: '.$folder.$files[$rand]); // Voila! 
    ?> 
    Now you're going to want to go to File>Save As and save the file as something like "Sig.php" or "[yourscreenname].php" and make sure you change the FileType box to read "All other files" -- failure to do this will cause your script to be saved as a TXT instead of a PHP - Ergo, it won't work.

    You won't need to edit this script in order to get a working signature - so just leave it as is.

    Step 2 - Organization!
    Make a folder on your desktop. Name it something short but memorable. A name like "sig" would work fine.

    Once you've made this folder move your PHP script and any signatures you wanted to use into it.

    Step 3 - "lol, internet"
    Now it's time to put all of the files in your "sig" folder online!

    To do this, you'll need to access your webhost/fileserver or whatever it is you use to store your files online with. [please note that image hosting websites will not work, because you need all of your signatures to be in a folder by with the php script and no other images]

    Once you're on your webhost, use your filemanager or FTP (if possible) to create a new folder on the server called "sig" and copy all of the files from your desktop's "sig" folder into it.

    If you own your own website; your files can now be found at http://whateveryourwebsiteis.xxx/sig

    If, like most people, you're on a shared hosting package such as geocities (which will be shut down later this year, FYI), you're files will be found at http://yoursub.yourhost.xxx/yoursub/sig -- it all depends on your hosting arrangement, but I trust you get the general picture, right?

    Step 4 - Sign here...
    Now comes the tediously daunting, one-line of code part.

    Look out, because this one takes some editing. You're going to want to edit out the address to point towards your sig.php file. Anyway here's the codes:

    For Most Forums:
    Code:
    [img]http://whereveryourstuffisat.site/sig/sig.php
    For Emails/Myspace/Websites:
    Code:
    <img scr="whereeveritisyourstuffishosted/sig.php" alt="Whatever you want the mouse-over to say"
    Just edit the code to point towards your PHP script and presto! You're done! Well, all except for Step 5...

    Step 5 - Smile.
    You now have a random image signature. Be pleased with yourself.





    Notes to the user:

    You can have as many signatures as you want to, and can add images to the signature folder at any time, without changing any scripting, and they will automatically start to appear in your signatures.

    This script works with all images, of course, so there's nothing defining it to just be used with signatures. If you wanted a random avatar for each of your posts, it'd be as simple as pointing you avatar towards a php script. And if you wanted to get high-tech and have a website header that loaded a random banner for each viewer, you could certainly do that.

    None of the filenames for you images really matter, but if you want the images to load faster for your viewers (highly suggested) you may want to make sure the image names do not contain any spaces, and it helps to keep them short. My image names are just numbers.

    At this moment in time there is no way to set a prefference or probability to these images, which means I can't say I want image 11 to load 40% and the other 10 to load 5% -- All images have an equal chance of being displayed. So, the more images you have, the more random it is.

    Credit for the original version of this script goes to Matthew Mullengew who's work I found via google.
     
  2. djscoop

    djscoop Active member

    Joined:
    Feb 6, 2003
    Messages:
    4,051
    Likes Received:
    0
    Trophy Points:
    66
    nice work, that is a pretty cool idea. is there anyway to write a script that makes the sig image in a post change every few seconds, like a slideshow? once the script is read and the image is loaded can you make the script continue to run and cycle through more pics? I guess my question is that I really like this random image script, but can you make one that will cycle through multiple pics in the same signature?
     
  3. djscoop

    djscoop Active member

    Joined:
    Feb 6, 2003
    Messages:
    4,051
    Likes Received:
    0
    Trophy Points:
    66
    ha ha i've already refreshed this page five times to see all your different sig images...very cool dude!
     
  4. varnull

    varnull Guest

    Just an interesting observation.. I couldn't find a free hosting option which runs php .. They do, but only in their paid services, never for free .. I guess because it's something script kiddies can exploit to execute random scripts through browser holes?
     
  5. djscoop

    djscoop Active member

    Joined:
    Feb 6, 2003
    Messages:
    4,051
    Likes Received:
    0
    Trophy Points:
    66
    so a free site like geocities won't work?
     
  6. Vicious88

    Vicious88 Regular member

    Joined:
    Jan 25, 2007
    Messages:
    274
    Likes Received:
    0
    Trophy Points:
    26
    @djscoop & varnull: DBHOST (at dbhost.info) offers free webhosting AND php support. I don't use them personally, so I don't know too much about what kind of packages they offer, but a friend of mine highly recommends them for small projects like this or online portfolios and resumes.

    Apparently, according my friend, they take a good while to getsigned on with -- sometimes a matter of weeks. In any case, they're who were recommended to me.
     

Share This Page