x10Hosting Forums

Corporate Free Hosting for the Masses.



Register

Reply
 
LinkBack Thread Tools Display Modes
x10Hosting Member

Join Date: Apr 2008
Posts: 1
Credits: 19
cellporn is on a distinguished road
Quote  
05-11-2008, 06:16 AM
Simple Banner Rotator

PHP powered banner rotator using the power of flat files (txt files).
This week we will build a simple banner/image rotator. We will be doing this using flat files (txt files) and a couple of file functions in php.
Here is what the banner txt file should look like, you simply just put one image/link pair per line. The "[$]" seperator is used to split apart the img/link pairs. We use this interesting seperator to ensure it is not going to be contained in the link or image reference.

google.gif[$]http://www.google.com
friendster.gif[$]http://www.friendster.com
yahoo.gif[$]http://www.yahoo.com

First off, define the variables for this project
//// Customizable Settings for banner script//$banner_txt_file = 'my_banners.txt'; // Our txt file of banner references$banner_links = true; // Show banner as just image or with link (href)Now lets set up a function to contain all of our banner code and make it easier to call in the future.
<?
function display_banner() {
// use 'global' to reference our preset variables
global $banner_txt_file, $banner_links ;
mt_srand((double)microtime() * 100000);
$banners = file($banner_txt_file);
$count = count($banners);
$random = rand(0, $count - 1);
$banner = $banners[$random];
$banner_parts = explode("[$]", $banner);
$banner_img = $banner_parts[0];
$banner_link = $banner_parts[1];
$banner_html = "<img src=\"" . $banner_img . "\" />";
// build img tag
if($banner_links)
{ $banner_html = "<a href=\"" . $banner_link . "\">" . $banner_html . "</a>";
}
return $banner_html;
// return the html code
}
?>Now let's take a moment to explain what is happening in those last few lines. First off we define a few global variables to gain access to them in the function (scope issue).
Then we use mt_srand() to create a random seed, and ultimately allow us to pick a random banner image. Now we begin the file opening process and start reading in our banners and links. We then take these lines of link/img pairs and choose a random one to display. Finally we build our necessary html to display the banner and add the link info if $banner_links is set to true.
Note: Make sure you "chmod" the banner txt file, so it can actually be read.
To display a random banner, you simply place this PHP code somewhere in your file
print display_banner();Thats it, you now have a working php banner script... next time we will create a feature packed version with MySQL, counters and all sorts of goodies.

Last edited by cellporn; 05-11-2008 at 06:20 AM.
Reply With Quote
cellporn is offlineReport Post
x10Hosting Member

Join Date: Mar 2008
Posts: 94
Credits: 604
tektrnica is on a distinguished road
Quote  
05-11-2008, 05:33 PM
Re: Simple Banner Rotator

credit where credit is due...

http://scriptplayground.com/tutorial...anner-Rotator/
__________________
Reply With Quote
tektrnica is offlineReport Post
Dan
X10 Account Manager

Dan's Avatar

Join Date: Aug 2007
Posts: 1,128
Credits: 10,335
Dan has a brilliant future
Location: UK

Quote  
05-12-2008, 03:11 PM
Re: Simple Banner Rotator

Yeah, not exactly yours...
But good anyway.
__________________
Dan
Senior Moderator


DO NOT PM ME OR ANY OTHER STAFF UNLESS ASKED TO DO SO.



Reply With Quote
Dan is offlineReport Post
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
x10Hosting Ads as a Banner in Joomla! s906201 Tutorials 10 08-26-2008 08:07 PM
Two very simple php file upload scripts-Free Symbian.Ankit Scripts & 3rd Party Apps 2 02-20-2008 10:55 AM
Seas2Success - Custom Banner Offer! loveboat Ads & Offers 9 02-09-2008 12:34 AM
Banner Advertisments From 100 Creds fitzysit The Marketplace 44 01-30-2008 01:04 AM
how do I include a php banner rotator? vigge_sWe Scripts & 3rd Party Apps 10 11-02-2007 05:57 AM


All times are GMT -5. The time now is 06:09 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC7
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

Mortgages | Yahoo Personals | Ringtone | Loans | Loans