__Dj_-k1ll3r__ Super Moderator
Posts : 63 Points : 187 Reputation : 0 Join date : 2011-07-18
| Subject: Banner Rotation in (php) Mon Jul 18, 2011 2:28 pm | |
| Display random banners on your site is to use the rand () function and assign each image and link a number. The banner that corresponds to the random number generated is then displayed.
PHP Code: - Code:
-
<?php session_start();
$links = array( "http://www.google.com", "http://www.msn.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",
);//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>’;
?>
OR
PHP Code: - Code:
-
$Img1 = "http://yoursite.com/image.jpg"; $Url1 = "http://www.identity.st"; $Img2 = "http://www.hissite.com/bannerA.gif"; $Url2 = "http://www.about.com"; $Img3 = "http://hersite.com/MyImage.gif"; $Url3 = "http://php.about.com"; $num = rand (1,3); $Image = ${'Img'.$num}; $URL = ${'Url'.$num}; Print "<a href=".$URL."><img src=".$Image." border=0></a>"; place the PHP include on your page where you want the banner rotator.
PHP Code: - Code:
-
<?php include ("banner-rotator.php"); ?> | |
|