vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Want to randomly select a header image for each session (https://vborg.vbsupport.ru/showthread.php?t=121940)

sof-guild 07-24-2006 02:18 AM

Want to randomly select a header image for each session
 
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:

PHP Code:

<?
$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:

Code:

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:

HTML Code:

<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.


All times are GMT. The time now is 10:47 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00958 seconds
  • Memory Usage 1,713KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_html_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete