Intro
This post will explain a method to create a rotating signature that you can use on forums. For an example, just check out my signature, then refresh the page a few times. This method will also work for avatars.
Requirements
Not only do you need a server to host the images, but it also has to support PHP, and configuration with .htaccess.
I can only use IMG tags in my signature! How do I link to a script?
We are going to be linking to an image! Through the magic of PHP, we will be giving the script a JPEG extension.. and then setting the server to process PHP code in JPEG files in the specified directory!
Getting Started
First you must gather together the images you would like to use for a signature. The script will randomly select one to display each time the page is refreshed. For this example, they will all be jpg files. Create a new directory ('rotate' in this example) on your server and copy the files to it.
Creating the Script
Copy the following code into a new file:
Code: Select all
<?php
$dh = opendir(".");
while (false !== ($file = readdir($dh)))
{
if (preg_match('/\.jpg$/i', $file) and $file != "rotate.jpeg")
{
$filelist[] = $file;
}
}
srand((double)microtime()*1000000);
$picnum = rand(0, sizeof($filelist) - 1);
$fn='http://www.yoursite.com/rotate/rotate.jpeg';
header('Content-type: image/jpg');
header('Cache-control: no-cache, must-revalidate, no-store');
header('Content-disposition: filename='.$fn);
header('Pragma: no-store');
header("Location: " . $filelist[$picnum]);
closedir($dh);
?>
In the above code, make sure to change the website path to point to the exact location of your rotate.jpeg!
Here is an example directory listing now:
rotate.jpeg (really just a script file with a jpeg extension)
sig1.jpg (your real sig files 1, 2, and 3)
sig2.jpg
sig3.jpg
Configuring Your Server
Now you have to trick your server into treating files with the JPEG extension as PHP scripts, but only for this directory. Create a new .htaccess file (thats (period)htaccess - no prefix - windows will not let you create a file without a prefix so you may have to rename it properly once its uploaded), and upload it into your 'rotate' directory.
Insert the following code in to the .htaccess file:
Code: Select all
RewriteEngine off
AddType application/x-httpd-php .jpeg
Using It
Now just use 'http://www.yoursite.com/rotate/rotate.jpeg' (or however you changed it for your server) as your signature!
Notes
- The script handles any number of images
- The code is case-sensitive!
- If you want GIFs, the code has to be modified
I am sure I will think of more to add!