nerges web design massachusetts connecticut

Random Image Generator

So I had the need to randomize a banner. Not too uncommon one would think. But to get it work cross-browser was another story. I did end up, however, finding a VERY easy script from a website called Personified with an article called "Simple Random Header Images for Your Blog". But instead of using the function rand I'm using the function mt_rand. Supposedly it gives a better randomization.

The basic idea is to put whatever images you want to randomize in the same folder, anywhere on your server. Name them something similar but with numbered in order. So something like banner1.jpg, banner2.jpg, ... banner55.jpg.  Then when you call an image you script it like

http://images_folder_path/banner<?php echo(mt_rand(1,55)); ?>.jpg

But your pages must be in php in order for this to work. Not only is this the EASIEST way to do this but it also WORKS! 

 
copyright © 2004-2007 Nerges Design - Valid CSS - Valid XHTML -