How to display random image on a webpage

From: danleephoto <athiril_at_gmail.com>
Date: Sun, 24 Aug 2008 05:19:14 -0000

Hi, this is the simplest way to do it.

I'm sure youd be familiar with the IMG tag, that you can change the
diretory and filename to what you want.

change the 3 in rand()%3 to the number of images you have.

(I hope the code shows up as plain text on here)

<?php

srand(time());
$random = (rand()%3)+1;

?>

<img src="images/myimage_<?php echo $random; ?>.jpg">

You can plug this in wherever you want the image to be, and just have
.php instead of .html, or just leave it as .html

If it doesn't work as .html you just need to set up the mime type in
your hosting config to display as php (which will not break anything),
very easy to do.

The benefit of this way, is when you've finished it and got it working,
it works for everyone, indentically, on all browsers, even for people
running a Windows 95 and IE4.
Received on Sun Aug 24 2008 - 00:04:49 CDT

This archive was generated by hypermail 2.3.1 : Sat Nov 30 2019 - 17:52:28 CST