This is a
simple way to display images on your
web page using PHP. Each time the page is refreshed, the script will
choose one image from a list of images to display on your page.
Step One
Create your web page as normal but save it with a php extension,
for example, randomimage.php.
Step Two
Create a directory for your images and upload your images into
that directory.
Step Three
Copy this code and paste it into your page where you want the
images to be displayed.
<script language="JavaScript" type="text/javascript">
// Random Image Script by www.paintedpixels.com
var url = "www.yoursite.com/randomimage/images/";
Notice how the format stays the same. Only the number in square
brackets increases by 1 for each image.
var randImg=Math.floor(Math.random()*(imageArray.length));
var imgurl = "http://" + url + imageArray[randImg];
document.write('<img src="' + imgurl + '">');
These three lines choose a random image from the array, works
out the full url to your image and prints the image to your web page.
Do not change these three lines.
You are now finished!
Your page should look similar to this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
< html>
< head>
<title>Random Image</title>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
< /head>
<body>
<h2 align="center">My Images</h2>
<script language="JavaScript" type="text/javascript">
// Random Image Script by www.paintedpixels.com
var url = "www.yoursite.com/randomimage/images/";