Random Single Image Display On Page Reload Using PHP

by Hiroshi on June 18, 2008

in Randomizing, Rotating Content

Very small yet wow kind of script that takes a folder and displays random script image at every time page reloads.

PHP Code

$files = glob("images/*.*");
mt_srand( (double) microtime() * 1000000 );
$num = mt_rand(0, count($files)-1);
echo '<img src="'.$files[$num].'" alt="" />';

In this example ‘images’ is the folder containing all the images. Every time page reloads, it will display different image.

Random Single Image On Page Reload PHP Script Download

Related Posts

Previous post:

Next post: