Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
Simple Ad Rotator (0 Comments)
Admin: Posted Date: April 4, 2010

Creating a simple ad-rotator. In this, ads are stored in a text file and picked randomly by this PHP code. This tutorial will show you how to create a simple ad rotator system using PHP and a flat-file database.

Overview: Creating a simple ad-rotator, the ads are stored in a text file and picked randomly by this PHP code.

Most of the webmaster use banner ads, we will be creating a very simple banner rotator, which picks up randomly one ad from the banner file and displays it, this file can be called in any other page to display the banners.

We will be storing banner ads in a text file banner_ads.txt


banner_ads.txt

null
~

Click here for Commission Junction
~

null
~

Dotster $14.95 Domain Name Registration
Note that the banners are seperated by ~ in our banner file.

ad_rotator.php

$fcontents = join ('', file ('banner_ads.txt'));

$s_con = split("~",$fcontents);

$banner_no = rand(0,(count($s_con)-1));
echo $s_con[$banner_no];
?>

The above 'ad_rotator.php' can be included in any PHP page to display a banner ad by using include 'ad_rotator.php'; tag wherever banner is required.

The above concept can be also be used to display random quotes etc, just modify the banners_ads.txt with the random content you want.


 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: