PDA

View Full Version : Want to randomly select a header image for each session


sof-guild
07-24-2006, 02:18 AM
I have some experience with PHP, but none with vB. I've just been reskinning my first forum, and would like to be able to randomly select a different header image for each session. I know how I would do this in PHP, but am hoping someone can help me translate it to PHP.

Here's how I would approach the top of each page in PHP:


<?
$headerimg = 0;
$maximages = 6;
if ($_SESSION['header'] != "") {
$headerimg = rand(0,$maximages);
$_SESSION['header'] = $headerimg;
} else {
$headerimg = $_SESSION['header'];
}
?>


Then, in the header, I could just have <img src="/_images/header<?= $headerimg ?>">

Where do I put this code in my forum to set the variable, and how do I successfully retrieve the variable in the header template?

Thanks for your help.

ConqSoft
07-24-2006, 03:11 AM
If you're using a version of vBulletin before 3.5.x, I can't help you. For 3.5.x and up, create a plugin at the global_start hook and place your code there.

I generate a random number to grab a random header on my site. Here's the code I use in my plugin:

mt_srand((double)microtime()*1000000);
$fb_header_random = mt_rand(1, 9);

Then, the $fb_header_random variable will be available to me in the header template. (or any other template since I'm executing at the global_start hook)

I use this in my header:


<img alt="" src="/forums/images/header/$fb_header_random.jpg" height="94" width="899" />

sof-guild
07-24-2006, 04:45 AM
Thanks! That worked just fine.