| Coding Forum Problems with your code? Let's hear about it. |
03-02-2006, 02:32 AM
|
#1 (permalink)
|
|
Individualist
Join Date: 09-27-03
Location: Japan, mostly
Posts: 42,321
|
Simple Banner Rotation Script
On one site I used to own, we had the banner set to rotate on every page view. No tracking, no complex script.
Anybody know of the code used to do this?
|
|
|
03-02-2006, 03:06 AM
|
#2 (permalink)
|
|
Individualist
Join Date: 09-27-03
Location: Japan, mostly
Posts: 42,321
|
|
|
|
03-02-2006, 03:10 AM
|
#3 (permalink)
|
|
Individualist
Join Date: 09-27-03
Location: Japan, mostly
Posts: 42,321
|
Actually that was perl and I need PHP. So I found a PHP version.
PHP Code:
<?php
/* Banner Simple, Version 1.0
* by Dan Kaplan <dan@abledesign.com>
* Last Modified: January 10, 2003
* --------------------------------------------------------------------
*
* USE THIS LIBRARY AT YOUR OWN RISK; no warranties are expressed or
* implied. You may modify the file however you see fit, so long as
* you retain this header information and any credits to other sources
* throughout the file. If you make any modifications or improvements,
* please send them via email to Dan Kaplan <dan@abledesign.com>.
* --------------------------------------------------------------------
*/
$base_dir = '/path/to/www/';
$img_url = 'http://www.mysite.com/images/ads';
// add any banner sizes (width x height) that you will use:
// IAB Standards & Guidelines: http://www.iab.net/standards/adunits.asp
$banner_sizes = array ("468x60", "100x60", "100x38", "300x250", "250x250", "240x400", "336x280", "180x150", "468x60", "234x60", "88x31", "120x90", "120x60", "120x240", "125x125", "160x600", "120x600");
$srand_called = FALSE;
$last_file = '';
$array = '';
function get_banner($size='') {
global $base_dir, $img_url, $banner_sizes, $srand_called, $last_file, $array;
if (empty($size) || !in_array($size, $banner_sizes)) {
$size = "468x60";
}
$size_split = explode("x", $size);
$width = $size_split[0];
$height = $size_split[1];
if (empty($last_file) || ($size != $last_file) || !is_array($array)) {
// if calling muliple banners on one page, no need to read in the same file repeatedly. so,
// if the last banner file read in is the next one called, pull the $array array from memory.
$file = $base_dir."/mybanner_".$size.".txt";
if (!file_exists($file)) {
// could not load the banner file, so create a default blank image and exit
$banner = "<img src=\"\" width=\"$width\" height=\"$height\" border=\"0\" alt=\"broken image\">";
return $banner;
}
$array = file($file); // read $file into an array
$last_file = $size; // save the last read-in file into memory
}
if (!$srand_called) {
// slightly less random without this; srand() should only be called once for multiple banners
mt_srand ((double) microtime() * 1000000);
$srand_called = TRUE;
}
$rand = mt_rand(1, count($array)-1); // start at 1 to ignore comment line
$line = chop($array[$rand]);
# URL | target="_blank" (1/0) | off-site image (1/0) | image | Alt text
$banner_split = explode("|", $line);
$URL = $banner_split[0];
$blank = $banner_split[1];
$off_site = $banner_split[2];
$image = $banner_split[3];
$alt = $banner_split[4];
if ($blank == 1) {
$target = "target=\"_blank\"";
} else {
$target = "";
}
if ($off_site == 1) {
$image = $image;
} else {
$image = "$img_url/$image";
}
$banner = "<a href=\"$URL\" $target><img src=\"$image\" width=\"$width\" height=\"$height\" border=\"0\" alt=\"$alt\"></a>";
return $banner;
}
?>
http://abledesign.com/programs/banner.php
What do you think?
|
|
|
03-02-2006, 03:30 AM
|
#4 (permalink)
|
|
aka Colleen
Join Date: 03-25-04
Location: Canada
Posts: 5,925
Latest Blog: None
|
I have a simple one on a client's site and it's just a javascript you insert into the same page the images are on that you want rotated. Do you want PHP for a reason?
|
|
|
03-02-2006, 03:31 AM
|
#5 (permalink)
|
|
Individualist
Join Date: 09-27-03
Location: Japan, mostly
Posts: 42,321
|
Not all people have JS enabled - would piss off advertisers.
|
|
|
03-02-2006, 03:39 AM
|
#6 (permalink)
|
|
aka Colleen
Join Date: 03-25-04
Location: Canada
Posts: 5,925
Latest Blog: None
|
I figured that's why. The one you posted above looks fine.
|
|
|
03-02-2006, 03:42 AM
|
#7 (permalink)
|
|
Individualist
Join Date: 09-27-03
Location: Japan, mostly
Posts: 42,321
|
Can you try it out somehwere?
Like, um, on vB?
Sweetie 
|
|
|
03-02-2006, 03:51 AM
|
#8 (permalink)
|
|
aka Colleen
Join Date: 03-25-04
Location: Canada
Posts: 5,925
Latest Blog: None
|
What is VB? Yeah I can after you tell me, lol.
|
|
|
03-02-2006, 04:25 AM
|
#9 (permalink)
|
|
Individualist
Join Date: 09-27-03
Location: Japan, mostly
Posts: 42,321
|
Any vBulletin board. Like one of yours or one of mine 
|
|
|
03-02-2006, 04:27 AM
|
#10 (permalink)
|
|
aka Colleen
Join Date: 03-25-04
Location: Canada
Posts: 5,925
Latest Blog: None
|
hmm ok. One of yours preferably.
|
|
|
03-02-2006, 04:32 AM
|
#11 (permalink)
|
|
Individualist
Join Date: 09-27-03
Location: Japan, mostly
Posts: 42,321
|
K
You need Admin permissions or ftp too?
|
|
|
03-02-2006, 04:41 AM
|
#13 (permalink)
|
|
aka Colleen
Join Date: 03-25-04
Location: Canada
Posts: 5,925
Latest Blog: None
|
Ok, gee, the skank forum, my day has just been made complete. 
Last edited by Kalina : 03-02-2006 at 04:44 AM.
|
|
|
03-02-2006, 04:44 AM
|
#14 (permalink)
|
|
Individualist
Join Date: 09-27-03
Location: Japan, mostly
Posts: 42,321
|
LOL 
|
|
|
03-02-2006, 04:44 AM
|
#15 (permalink)
|
|
aka Colleen
Join Date: 03-25-04
Location: Canada
Posts: 5,925
Latest Blog: None
|
Hurry, make me an admin, my eyes are burning!!  lol.
|
|
|
03-02-2006, 04:48 AM
|
#16 (permalink)
|
|
Individualist
Join Date: 09-27-03
Location: Japan, mostly
Posts: 42,321
|
You are admin, girl.
|
|
|
03-02-2006, 04:51 AM
|
#17 (permalink)
|
|
aka Colleen
Join Date: 03-25-04
Location: Canada
Posts: 5,925
Latest Blog: None
| |