Gatzet.com

Gadget, Free Software, Reviews

PHP Code For Banner Rotator

This php code creates simple banner rotator for your site. Just write a few code lines and put it on the page you want. Using this code your page will be more dynamic as it display different banner each time a visitor visiting your site. I found this code from papaface posting and will use it on my blog.

<?php
session_start();

$links = array(
"http://www.google.com",
"http://www.msn.com",
"http://forums.digitalpoint.com"
);
//add a new link for the banner to a new line in the same format as above

$images = array(
"http://www.google.co.uk/intl/en_uk/images/logo.gif",
"http://stc.msn.com/br/hp/en-us/css/35/decoration/msn_b.gif",
"http://forums.digitalpoint.com/images/misc/dps_logo.gif"
);
//add a new image link for the banner to a new line in the same format as above
//——– DO NOT EDIT BELOW THIS LINE———-
$count = count($links) -1;

$randnum = mt_rand(0,$count);

if ($randnum == $_SESSION['randnum'])
{
$randnum = mt_rand(0,$count);
}
$_SESSION['randnum'] = $randnum;
echo ‘<a href="’.$links[$randnum].’"><img style="border:none" src="’.$images[$randnum].’" /></a>’;

?>

 

Posted on January 6th, 2008   Tags: · , ,

4 comments for this entry ↓

  • 1 IndoDX // Jan 6, 2008 at 10:49 pm

    Perfect, I will use it ;)

  • 2 Easy Banner Rotator using Javascript | Gatzet.com // Oct 21, 2008 at 7:10 am

    [...] order to provide rotating ads banner on this blog, I was using php banner rotator code until I began to use wp-super cache plugin. Since the wp-cache plugin creates an html static [...]

  • 3 Ezdate123 // Jan 31, 2009 at 2:27 pm

    Thanks for the code tip. I will try it on my site….Mike

  • 4 chirag // Jun 28, 2009 at 8:38 am

    nice code!! images change after page refreshed!!
    thanx

Leave a Comment