Rotating Banners

John1

Paragon
Joined
Aug 29, 2009
Messages
1,629
Reaction score
0
FP$
6
I see a lot of people posting new threads here asking about rotating banner scripts, when they could easily be found using a quick google search.

Fortunatly for some, I have decided to post the one that I use on ForumLair.com - look to the right of the logo.

Code:
<script language="Javascript">
<!--
// Content made by donace
// For ForumLair.com

var currentdate = 0;
var core = 0;

function initArray() {

this.length = initArray.arguments.length;
  for (var i = 0; i < this.length; i++) {
  this[i] = initArray.arguments[i];
  }
}

link = new initArray(
"http://URL HERE",
"http://URL HERE",
"http://URL HERE",
"http://URL HERE"
);

image = new initArray(
"http://IMAGE URL HERE",
"http://IMAGE URL HERE",
"http://IMAGE URL HERE",
"http://IMAGE URL HERE"
);

text = new initArray(
"ALT TEXT HERE",
"ALT TEXT HERE",
"ALT TEXT HERE",
"ALT TEXT HERE"
);

var currentdate = new Date();
var core = currentdate.getSeconds() % image.length;
var ranlink  = link[core];
var ranimage = image[core];
var rantext  = text[core];

document.write('<a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');

//-->
</SCRIPT>

If you need more than 4 images, just add a new line for the URL, IMAGE URL and ALT TEXT. This script rotates on every refresh.
 
Thanks 🙂 Might have to look more into the code as I want to make it so if you are a "VIP" You don't see advertisements 🙂
 
Might be just me, but I do not see anything change on the link provided upon a refresh.
 
The banner and link change when you refresh, you need to add 4 banners and links before you get a different one each refresh.
 
Hee,

You said in your initial post that you can see it in action on your forum. However when I visit your forum, I do not see any rotating banners no matter how often I refresh.
 
That is because there is only 1 banner added to the service at the moment, all others banners have been completed.
 
Raymond said:
Thanks 🙂 Might have to look more into the code as I want to make it so if you are a "VIP" You don't see advertisements 🙂

If you are using vBulletin add this code around the script:

Code:
<if condition="$bbuserinfo['usergroupid'] == 1">
<p>SCRIPT CODE</p>
<else />
<if condition="$bbuserinfo['usergroupid'] == 2">
<p>Advertisements Disabled!</p>
</if>
</if>

Not tested, so don't know if it works or not. Remember to change the numbers to the actual usergroup number.
 
I use a Php script to do the same thing.

Simply save it as index.php and place it in a folder called "rotate.gif ". Upload the folder to your host. FTP any images you want rotated into the "rotate.gif" folder. Now just enter the path for "rotate.gif as you would any image link.

The folder with the .gif extension spoofs the browser into thinking it is an image and instead serves up one of the images. No need to ever edit the file to add images.

here is the script:
Code:
<?php
//visit prjx1.com for your scripting needs
if ($dir = opendir("."))
{
$list = buildimagearray($dir);
displayrandomimage($list);
}

// This function reads all the files in the current directory and adds all image files to the array $list[]
function buildimagearray($dir)
{
while (false !== ($file = readdir($dir)))
{
if (!is_dir($file) && getimagesize($file))
{
$list[] = $file;
}
}
return $list;
}

// This function selects a random image, determines the mime type, opens the file for reading,
// and then outputs the image
function displayrandomimage($list)
{
srand ((double) microtime() * 10000000);
$sig = array_rand ($list);

$size = getimagesize ($list[$sig]);
$fp = fopen($list[$sig], "rb");

if ($size && $fp)
{
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
}
}
?>
 
Thanks for sharing those banner rotation scripts with us.

Just a word of caution to anyone who ".. save it as index.php.." be careful that you don't upload that page to your main directory (probably public_html) and overwrite your site's homepage with it. This may sound obvious but I know one fool (me) who did this in the past.
 
Exactly as Fergal says, you can save it as something like banners.html and have it included in the script, or just add the HTML code straight to your template, it will work on most forum scripts.
 
Back
Top Bottom