Create a banner rotator with PHP
PHP is a powerful server-side scripting language for creating dynamic and interactive web sites. You can find free PHP scripts that lets you add interactivity to your web site which makes your site more interesting and that causes repeat and loyal visitors.
PHP is widely-used, free, and is an efficient alternative to competitors such as Microsoft's ASP. The great thing about PHP is that it is perfectly suited for Web development and can be embedded directly into the HTML code. That's right, you can use it with HTML.
The PHP include function
PHP can make life so much easier for anyone that builds and administers their own web site. The larger your site grows the more you need PHP. Especially the PHP include function. With the PHP include function you can make changes to one file, such as the menu, instead of changing the coding of each and every page. Instead of writing the entire code for your menu on every page of your web site, you simply add <?php include ("your file.php"); ?> and your done. You can make changes to this file without touching any of the pages on your web site and the changes appear throughout your site. Great stuff.
The banner rotator
One of the many PHP scripts that I use, and one of my favorites, is a PHP banner rotator. I use the banner rotator to automatically change the ads of products that I sell on my web sites. Each time the page is reloaded a new ad appears. This keeps your page fresh with new content, plus it gives your ads maximum exposure. You can see a PHP banner rotator in action just above this article.
The code for the banner rotator. You can add as many banner images to the rotator as you like just make sure that the rand number is equal to the number of banners. For example, if you have 6 banners, the rand number should be $num = rand (1,6,);
<?php
$Img1 = "http://www.(the source of the image)";
$Alt1 = "[advertisement] (place your alt text here)";
$Url1 = "http://www. (the url of the link)";
$Img2 ="http://www.pro-dezign.com/images/banner.jpg";
$Alt2 = "[advertisement] pro-dezign web development";
$Url2 = "http://www.pro-dezign.com/index.html";
$num = rand (1,2);
$Image = ${'Img'.$num};
$Alt = ${'Alt' .$num};
$URL = ${'Url'.$num};
Print "<a href=\"".$URL."\"><img src=\"".$Image."\" alt=\"".$Alt."\" /</a>";
? >
This PHP banner rotator validates with W3C. Just place the PHP include on your page where you want the banner rotator.
<?php include ("banner-rotator.php"); ?>
Have fun with ths great script.
If you liked this article, please add it to:Social Bookmarking


