random
Moderator: General Moderators
There are a couple of ways to do this, the easiest is probably to store the filenames of each of the possible images in an array, then use code like this (save as a script in the same folder as the images).
Then, in your HTML, do this:
Code: Select all
<?php
//Assign each image to a value in the array
$pics = array('img1.jpg', 'img2.jpg', 'img3.jpg');
//Choose a random number to use with the array
srand((double)microtime()*1000000);
$img = rand(0, sizeof($pics) - 1);
//Send the page the right file
header('Location: ' . $pics[$img]);
?>Code: Select all
<img src="scriptname.php' />