random
Posted: Thu Jan 08, 2004 10:45 pm
i was wondwerin how to make a random image appear on a site
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
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' />