Vectorials
Flash Perfection
3D Lessons
Tutorialkit
Markup Tutorials
Learn PHP
network
adv banner
Web Programming  Home Web Programming PHP Random Images
rss

Random Images

Author: Ethicsdesigns.com More by this author


Random ImagesEver wanted to make links, or banners appear on your site in a random order? Well here's a simple script that will do just that.

1. This script can be used as a include, to make updating your images easier, or you can just use the code directly on the page. In this example we will use it as a include.

Insert this code into the include:

<?
$banner[] = "<a href="URL" target="_blank"><img src="IMAGE" alt="" border="0" width="88"
height="31"></a>";
echo $banner[array_rand($banner)];
?>

Before you save the include make sure there's no other code in the file, so get rid of all the tags and whatnot. Then just paste that code into the blank field. Save your file as a .PHP

2. Now to explain what all that means. URL - You replace this tag with where you want the image link to take you. ex. (http://www.ethicsdesigns.com) IMAGE - Replace this with the location of the image you want to use. ex. (http://www.ethicsdesigns.com/image.gif)

You will also have to change the size of the width and height for each image, just edit:

width="88" height="31"

3. Now this is only for 1 image, how can you randomize only 1 image? Well here's how you add more, simply paste:

$banner[] = "<a href="URL" target="_blank"><img src="IMAGE" alt=""
border="0" width="88" height="31"></a>";

after the one that's already there, and replace the IMG tag and URL tag of the second image you would like to show randomly.

4. That's the Include part, now you need the code to put these images on your page:

<? include ("include.php") ?>

Just replace the 'include.php' with the location where you saved your include, paste the code on your page where you want the images to show up randomly and your set. Here's how the finished code should look. Include:

<?
$banner[] = "<a href="URL" target="_blank"><img src="IMAGE" alt="" border="0" width="88"
height="31"></a>";
$banner[] = "<a href="URL" target="_blank"><img src="IMAGE" alt="" border="0"></a>";
echo $banner[array_rand($banner)];
?>

Main:

<? include ("include.php") ?>

That's it, your done, too see an example look at the 3 links on the bottom of this page, they use the same script



Author's URL: www.ethicsdesigns.com

Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Add comments to "Random Images"