Banner Ad Rotators JavaScript & PHP Codes For Your Website!

Read Time:3 Minute, 16 Second

In this post I’m going to share some codes that will help you rotate multiple ads in one location. The banner rotators I’ll provide today will display a random ad each page load.

I’ll provide a JavaScript version and a PHP version, the JavaScript version is good for images & links like .png .gif .jpeg etc.. however, you wont be able to rotate ad code like a banner exchange. This is where the PHP version really shines, but in order for it to work your going to need a domain and hosting.

JavaScript Banner Rotators

This first rotator code is for text ads and will rotate text ads.

<script language=javascript>
/*
 +---------------------------------------------------------+
 | Ads For Blogger              Copyright :  www.oxaus.com |
 +---------------------------------------------------------+
 | This Copyright Notice Must Remains intact.              |
 +---------------------------------------------------------+
*/
 
var adtxt=new Array()
//insert here your text
adtxt[0]='Free Advertising For Your Website';
adtxt[1]='AUTO SURF SEO Exchange';
adtxt[2]='Banner Exchange Get 2000 Free Impressions';
 
var adlinks=new Array()
//insert here your links
adlinks[0]='http://www.funneledafiliate.com';
adlinks[1]='http://www.autoviewz.com';
adlinks[2]='https://www.sharemyads.com';
 
 
var xy=Math.floor(Math.random()*adtxt.length);
document.write('[Ad] <a href="'+adlinks[xy]+'" target="_blank">'+adtxt[xy]+'</a>');
</script>

This Second Code is For Banner Images and will rotate banner graphics

<script language=javascript>
/*
 +---------------------------------------------------------+
 | Ads For Blogger              Copyright :  www.oxaus.com |
 +---------------------------------------------------------+
 | This Copyright Notice Must Remains intact.              |
 +---------------------------------------------------------+
*/
var img_width = "300";
var img_height = "250";
var img_title = "Click Here";
 
 
var adimg=new Array()
//insert here your images src
adimg[0]='https://example.com/image.png';
adimg[1]='https://example.com/image.png';
adimg[2]='https://example.com/image.png';
 
var adlinks=new Array()
//insert here your links
adlinks[0]='https://example.com';
adlinks[1]='https://example.com';
adlinks[2]='https://example.com';
 
 
var xy=Math.floor(Math.random()*adimg.length);
document.write('<a href="'+adlinks[xy]+'" target="_blank"><img src="'+adimg[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'"></a>');
</script>

I actually created a simple blog a few years back with more information about these rotators – Click Here!.

PHP Banner Code Rotator

Now this is a bit more advanced but should still be fairly simple to understand.

First you need to create a ad-rotator.php file, in this file add the following code.

<?php
$bannerAd[1] = '<a href="https://freeleads.gr8.com" target="_blank">FREE: Get 200+ Free Email Leads - Click Here</a>';
$bannerAd[2] = '<div class="sMa1"></div><script async="async" src="//sharemyads.com/view/468/?uid=1"></script>';



$adCount = count($bannerAd);
$randomAdNumber = mt_rand(1, $adCount);
echo $bannerAd[$randomAdNumber];
?>

Then anywhere you want the ads to show you add the following code within the body tags of your website.

<?php include('./ad-rotator.php'); ?>

You Can Also Add The Full URL And Share It On Lots Of Your Sites.

<?php include('https://YOURWEBSITE.com/ad-rotator.php'); ?>

Now if you want to add more than 2 banners just follow the number sequence and add another banner. Also make sure each ad code is on one line, within the parentheses or you will get errors.

Ad code like google AdSense will not work I’m sorry! as it uses multiple lines and if you try compress it the ads wont display.

Conclusion

An Easy way to rotate your favourite banner exchange codes on your website maximizing on your digital real-estate. Oh, did I mention it’s free. Enjoy Mate.

One thought on “Banner Ad Rotators JavaScript & PHP Codes For Your Website!

Leave a Reply

Previous post Nifty Banner Exchange Trick Make Any Banner Exchange Ad Mobile Responsive
Next post Make Your Own PHP Website URL Rotator In Under 10 Lines Of Code!