Every now and then you want to randomize images, usually headers of sorts. This is pretty simple, with just 9 lines of PHP code you can rotate randomly between two images.
The PHP Script
Put this where you want to rotate your headers:
[php] ‘image1.gif’,
1 => ‘image2.gif’,
);
$image = $images[ rand(0,(count($images)-1)) ];
$output = ““;
print($output);
?>[/php]
This will rotate between image1.gif and image2.gif, which are located in /mysite/randomimages/ on your server.
Adding more images is easy, just continue to add lines, starting with the next digit and has a corresponding file name, in the $images = array(); segment. This is the same code with five images instead of two:
[php] ‘image1.gif’,
1 => ‘image2.gif’,
3 => ‘hello.gif’,
4 => ‘monkeys.gif’,
5 => ‘ninjas.gif’,
);
$image = $images[ rand(0,(count($images)-1)) ];
$output = ““;
print($output);
?>[/php]
Easy, isn’t it?
Now rotate those headers, photos, or whatnot!