Publishing System Settings Logout Login Register
Create a random banner advertisement rotator
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on November 6th, 2007
8896 views
PHP Coding
Today we will be creating a random advertisement rotator for your website. This will only require 1 php file and no database so it will be fairly simple.

We will learn through this tutorial:

How to create Array's
How to randomise Array's

Lets start by creating our file and naming it "ad.php". You can of course name this file anything you wish.


<?php // Start PHP so the server knows to parse anything below this as PHP
$ads = array(); // Start an array

$ads[] = '<a href="http://www.domain.com"><img src="/banners/ad1.gif" alt="domains banner" /></a>';
// We have created our first ad. We simple just put the format of the ad within an $ads[] variable. We can add as many ad's as we want as it is an array and won't overwrite the variable.

$ads[] = '<a href="http://www.domain2.com"><img src="/banners/ad2.gif" alt="domain2s banner" /></a>';
//We have no added another. Now we will display the ad's.

shuffle($ads);
// We will use the PHP function shuffle to randomise our advertisements.

echo $ads[0];
// We echo the first ad in the array. The array has been shuffled so the first ad will change.

?> //Stop parsing as PHP
 


We have now created our ad's. There are lots of things that are possible to do with this tutorial. You just have to think of them.

And thats the end on another tutorial. I hope you all learned something :).
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
GTMedia

Hey Im a young webdeveloper from scotland. If you want to know more about me. Visit www.mark-cole.net :)
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top