General Community > Scripting Help

Alternating Banner

(1/10) > >>

zagrom:
OK OK, I'm sure this has been asked somewhere before, so sorry I'm bringing it back up,
But I'm not particularly skilled in coding (in slowly understanding from manual MOD installs tho)

Anywho, basically what I want to know how to do, is make it so I can have "X" number of
banners for my site and when a page is loaded it picks one a random to show, I'm sure
this code is fairly simple, but any sources would be helpful, and if you could give me an
idea as to where I would need to place this code, that would be appreciated as well,

~Thanks ^^

zagrom:
Im sorry, Bump

I would like to get some feedback on
this, I have looked but have had trouble
finding anything

DavidCT:
Do you want it done in PHP (server side) or Javascript (client side)?  PHP is real simple.

$banner[1] = 'pic1';
$banner[2] = 'pic2';
$banner[3] = 'pic3';

print $banner[rand(1, count($banner))];

---

BTW, your signature banner is rediculous!  1116.41 KB (1143205 bytes) - 1 MEGABYTE.  It's cool, and I have broadband so it's not a slow issue, but man...

zagrom:
Well I was thinking of doing it
straight out of the Admin settings
by Modifying the index template,
where my banner pic is.

I assume that that is PHP, yes?

--- Code: ---   //begin html
   //Logoimage
   echo '<table cellpadding="0" cellspacing="0" width="100%" style="border-bottom: 1px solid #060000;">
         <tr class="bg">
                       <td><img src="', $settings['images_url'],'/oubanner1.gif" /></td>';
   
   //Custom code (theme settings)
   echo '              <td width="100%" align="right">', $settings['custom_code'], '</td>';
   echo '              <td width="200"><img src="', $settings['images_url'],'/ousidebanner.gif" /></td>';
--- End code ---
I belive this to be the top section of
my site, oubanner1.gif being my current banner

And should I change my sig?  XD

tyty1234:
You could make a php like David said, but here is one way I think is a little better.

Create a directory called banner, and upload all your banners that you are going to use.

Create a php file called "banner.php", and in that file, paste this code.

--- Code: ---<?php
// Load some variables...
$purl = 'http://yoursite.com/banner';
$path = '/home/var/public_html/banner/';

// Open up our images directory and prepare files.
$open = opendir($path);

// Loop the files.
while ($files = readdir($open))
{
$file[] = $files;
}

// Close the directory.
closedir($open);

// How many files are there? Count them!
$numfiles = count($file) -1;

// Create a random number.
mt_srand((double)microtime()*1000000);
$random = mt_rand(0, $numfiles);

// Get the random file name.
$img = $file[$random];

// Get the url.
$fpath = $path . '/' . $img;

// Get file extension.
$fext = strtolower(substr(strrchr($img,"."),1));

// Modify headers and read the image.
header("Content-Type: image/" . $fext);
readfile($fpath);
?>

--- End code ---
Make sure you change the $purl and $path to your site.

Then where you have your custom code, add this.

--- Code: ---<img src="http://www.yoursite.com/banner.php" alt="" />

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version