go top

MEGA Sale

  • Colection of 65 PHP scripts for $4.29 each

Get 65 PHP scripts in a bundle for $4.29 each!

View Offer

Banner and link rotation

Tuesday, 6th December, 2011  /  PHP Tutorials  /  8 Comments
I have many web sites and on most of them I run all kind of link/banner exchange or affiliate programs. Some of the affiliate programs perform much better and others are not that good. However, you will need a lot of time to find out which one perform better than the others. You will have to put a banner for the 1st affiliate program for few days and analyze its performance results. Then you will have to do the same for the other affiliate banners and at the end to choose the best one. Of course if you have 5 different banners you will need to spend 5 x 3 days each = 15 days to find out which one is the best.

What I would suggest is to randomly show all the banners during the first 3 days. At the end you will have the impressions, clicks, sales results for all of the banners and you can decide which one to use a lot sooner.

Now, what I am going to do is define PHP array with all the 5 affiliate codes. Then using the PHP rand(min,max) function I will randomly select one of these 5 array elements. The first parameter defines the minimum value that you want and the second parameter is for the maximum value that you want generated. In our case we need to use rand(1,5). All that has to be done now is to print the randomly selected array element.

<?php
$mybanners[1] = '<a href="http://www.affiliate1.com"><img src="banner1.jpg"></a>';
$mybanners[2] = '<a href="http://www.affiliate1.com"><img src="banner1.jpg"></a>';
$mybanners[3] = '<a href="http://www.affiliate1.com"><img src="banner1.jpg"></a>';
$mybanners[4] = '<a href="http://www.affiliate1.com"><img src="banner1.jpg"></a>';
$mybanners[5] = '<a href="http://www.affiliate1.com"><img src="banner1.jpg"></a>';

$id = rand(1,5);

echo $mybanners[$id];
?>
Share on:

8 Comments to "Banner and link rotation"

Redssu

Redssu / November 12, 2017 at 22:09 pm

Easy way:

 echo array_rand($mybanners) 

keith

keith / January 25, 2014 at 22:57 pm

Can you put a time on this so the image changes every ten seconds?

klever

klever / August 6, 2010 at 23:02 pm

they dont have a demo because its a free script

Jim

Jim / May 22, 2010 at 05:44 am

How would make this rotate only when the web page is re-loaded??

Pete

Pete / May 22, 2008 at 22:16 pm

All makes sense

Samuel

Samuel / April 25, 2008 at 13:03 pm

What if I want to rotate the links evenly?

sopha

sopha / August 4, 2007 at 06:49 am

The blog: echo $mybanners[$i];
Should chang to :echo $mybanners[$id]; to make it work.

arnold

arnold / August 24, 2006 at 02:21 am

Just wondering do you have actual demo?

Add your comment

Captcha

    Please, be polite and helpful and do not spam or offend others! We promise you will be treated the same way!

    Log in to your account to post your comments. If you still haven't joined our community yet, you can create your FREE account now!

    Posting tip:
    If you use code in your comments, please put it in these tags [php], [sql], [css], [js] PHP code example: [php] echo date("Y-m-d"); [/php]

    Thank you,
    PHPJabbers Team

    Free Scripts

    Add great new functionalities to your website with our Free Scripts collection.


    Free scripts

    PHP Scripts

    Check our extensive collection of top-notch PHP Scripts that will enhance your website!


    Commercial PHP scripts