All you have to do is the following:
- Create a folder called avatars in your site root with all the PNG images you want to use (I have forced this script to process PNG). Of course you can use any other name or path, but then you will need to change other references to it accordingly.
- Rename all the images with a consecutive number with leading zeroes (000001.png, 000002.png, 000003.png and so on...), all files names should be 6 chars long. Then change the number of images $random_avatar_n = 699; to reflect the total amount.
- Create a new file called avatar.php, paste in it the code from the box here below and then copy the file it in the folder you just created with all images (i.e.: yoursite.com/avatars/avatar.php).
<?
$random_avatar_n = 699;
if (function_exists(mt_rand))
{
$rand = mt_rand(1, $random_avatar_n);
}
else
{
$rand = rand(1, $random_avatar_n);
}
header('Content-type: image/png');
header('Cache-Control: no-store, no-cache, no-transform, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0, max-age=0', false);
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Pragma: no-cache');
echo file_get_contents(str_pad($rand, 6, '0', STR_PAD_LEFT) . '.png');
?>
- Alter your .htacces (in your root) by adding this line (change path and filenames accordingly):
- Go in your browser and just recall the avatar:
If you did everything correctly you should have something like this:
Once the page is loaded, just refresh it and the image should change...

I hope you like this script!
P.S.: I forgot to mention that you should carefully choose your images to not be too wide...
