Random banner


Okay heres how to make a page which shows random banners everytime you visit the page (or reload it).

PHP Code
  1. <?
  2. //Create an array so we can sort the banners out in order of 1, 2 and 3
  3. $banners= array("banner1.gif", "banner2.gif", "banner3.gif");
  4.  
  5. //Create a random number to use later on (must be from 0 to 2 if ur using 3 banners
  6. $randomnumber= rand(0, 2);
  7.  
  8. //Now time to make the random image
  9. echo "<img src='$banners[$randomnumber]'>";
  10. ?>


Thanks, please post comments and report any bugs or mistakes you find
ilyas-shezad's Avatar
Views:
2,418
Rating:
Posted on Wednesday 9th April 2008 at 07:22 PM
DanielXP
DanielXP's Avatar
PHP Code
  1. <?
  2. //Create an array so we can sort the banners out in order of 1, 2 and 3
  3. $banners = array("banner1.gif", "banner2.gif", "banner3.gif");
  4. $links = array("link 1", "link 2", "link 3");
  5.  
  6. //Create a random number to use later on (must be from 0 to 2 if ur using 3 banners
  7. $randomnumber = rand(0, 2);
  8.  
  9. //Now time to make the random image
  10. echo "<a href='" . $links[$randomnumber] . "'><img src='" . $banners[$randomnumber] . "'></a>";
  11. ?>
Posted on Wednesday 9th April 2008 at 06:31 PM
Dalez
Dalez's Avatar
Is there anyway to make it so they could all have a link? And when i mean link, i mean they all have different links..
Posted on Saturday 9th February 2008 at 02:50 PM
Liquidsteel
Liquidsteel's Avatar
Not Bad
Posted on Tuesday 16th October 2007 at 01:48 AM
Thug
Thug's Avatar
Works great, AND it looks REALLY good on my site...thank you for this tut.
Posted on Sunday 12th August 2007 at 05:14 PM
-=InSaNe=-
-=InSaNe=-'s Avatar
I will try it soon, but thanks because I needed something like that.