header left image   header right image

Home > Toolkit > Random Images

Random Image Generator

What is this?

A random image generator is a server-side include that you can put into the source of an html page that will randomly choose from multiple images that you've supplied each time a user views the page.

How do I use the generator?

You only need to put a server-side include into your web page where you want the image to appear. The include is: <!--#include file="random_image.php"-->

Next, simply copy the following line into an empty file and name it "random_image.php":

<img src="<?php print(rand(0,X)); ?>.jpg">

The only change you need to make is to change the X to one less than the number of images you are using. The character before the X is a zero, not an oh.

All images must be named with numbers starting with 0 and incrementing by one. Example: 0.jpg, 1.jpg, etc. They also must have a .jpg extension. If all images are .gif files, you can make that change in the random_image.php file. Currently, this script does not support more file type at the same time.

Finally, upload the random_image.php file, all the images you want displayed and the html file to the same directory. This script will not work unless you test it from the server.

For best performance, make all images the same height and width.

The only caveats to this is the page must be kept on the webpub server and you must follow the same steps as for other server-side includes. This may not work on departmental servers.

 

[Toolkit]   [ Publishing Help]   [Publisher Forum]   [Web Policies]  [Web Security]   [Brown Home]   [CIS Home]   [Home]


Page Last Modified: Tuesday, 23-Mar-2004 15:47:01 EST by CIS