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 :).