Announcement

Collapse
No announcement yet.

Random php background image (header)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random php background image (header)

    There are dozens of post detailing php_include template to use a php file in your forum. But, none of them worked for me to get a random background or image to work..

    To create a random background image in the header:
    1. Create a folder in your forum /images directory, I called mine header (/forum/images/header)

    2. In that folder I put a php file with the following code (found in this forum) and called it header.php
    Code:
     [i]<?php
            /*
            By Matt Mullenweg > http://photomatt.net
            Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
            Latest version always at:
            http://photomatt.net/scripts/randomimage
            */[/i]
    
             [i]// Make this the relative path to the images, like "../img"          or "random/images/".
            // If the images are in the same directory, leave it blank.
            $folder = '';[/i]
    
             [i]// Space seperated list of extensions, you probably won't have to          change this.
            $exts = 'jpg jpeg png gif';[/i]
    
             [i]$files = array(); $i = -1; // Initialize some variables
            if ('' == $folder) $folder = './';
            $handle = opendir($folder);
            $exts = explode(' ', $exts);
            while (false !== ($file = readdir($handle))) {
            foreach($exts as $ext) { // for each extension check the extension
            if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg,          case insensitive
            $files[] = $file; // it's good
            ++$i;
            }
            }
            }
            closedir($handle); // We're not using it anymore
            mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
            $rand = mt_rand(0, $i); // $i was incremented as we went along[/i]
    
             [i]header('Location: '.$folder.$files[$rand]); // Voila!
            ?>[/i]
    3. Put some images in the folder

    4. In your forums header template, I added a background in the table with the header.php file, like:

    Code:
    <!-- logo -->
    <a name="top"></a>
    <table border="0" width="$stylevar[outertablewidth]" height="100" cellpadding="0" cellspacing="0" align="center" [b]background="images/header/header.php"[/b]>
    <tr>
    <td align="$stylevar[left]" width="500" valign="middle"><a href="http://my_forum.com" title="My Forum"><img src="$stylevar[titleimage]" border="0" alt="$vboptions[bbtitle]: Title of My Forum" /></a></td>
    	
    	<td> </td>
    </tr>
    </table>
    <!-- /logo -->
    
    <!-- content table -->
    $spacer_open
    $_phpinclude_output
    Now, every reload shows a different background image and I didn't need the php_include template. You can also use this to have a random image vs. a background.

    I'm sure you could find this in the forum, but all I found was Steve referring users to read the manual and look at the php_include tutorial on vBulletin.org.

    - BT

  • #2
    Thanks for posting this, but it should be posted on www.vbulletin.org since it involves a custom PHP script.

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...
    X