How to Create and Use a PHP Banner Rotator
Browse articles:
Auto Beauty Business Culture Dieting DIY Events Fashion Finance Food Freelancing Gardening Health Hobbies Home Internet Jobs Law Local Media Men's Health Mobile Nutrition Parenting Pets Pregnancy Products Psychology Real Estate Relationships Science Seniors Sports Technology Travel Wellness Women's Health
Browse companies:
Automotive Crafts & Gifts Department Stores Electronics Fashion Food & Drink Health & Beauty Home & Garden Online Services Sports & Outdoors Subscription Boxes Toys, Kids & Baby Travel & Events

How to Create and Use a PHP Banner Rotator

How to create and implement a php banner rotator script in your Website.

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 Website. 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. This script can also be used as an image rotator or for displaying text.

Below is the code for the php banner rotator that I created and use on my Website. Feel free to copy and use this script if you like. To show how the code works the example below has only two banners. You can add as many banners to the rotator as you like just make sure that the rand number, which means random number, is equal to the number of banners. For example, if you have 6 banners, the rand number should be $num = rand (1,6,);

The first thing you need to do is copy the banner images into the image file in your root directory. If you are using affiliate code you can place the affiliate code in the rotator also. Be sure to place the image source <img src=""> and  URL <href> in the right places.

Next fill in your image location, your alternate text and the url of the link.

<?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.yoursite.com/images/banner.jpg";

$Alt2 = "[advertisement]  web development";

$Url2 = "http://www.link.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.  Save this banner rotator script in your include file of your root directory and use the include function to display it on your site. <?php include ("banner-rotator.php"); ?>. When you need to make changes to the script, add or remove banners, you simple make the changes to the script in your include file and the changes appear throughout your Website.

I hope you find this script useful.

Need an answer?
Get insightful answers from community-recommended
experts
in Web Design & Development on Knoji.
Would you recommend this author as an expert in Web Design & Development?
You have 0 recommendations remaining to grant today.
Comments (0)
ARTICLE DETAILS
RELATED ARTICLES
RELATED CATEGORIES
RECENT SEARCHES ON KNOJI SHOPPING