Mod Name / Version: Multiple Random Banners v1.1 (No Duplicates)
Description: This updated script will allow you to display multiple random images or banners on your site without ever showing duplicates, and it is also more user friendly now.
It is tailored to be used for UBBThreads via the generic or forum headers, although it can easily be used on any PHP page as well. (it looks like footer includes need to be added to the send_footer() function in ubbt.inc.php instead, or else it won't work - not sure why that is).
Instructions ============
1) Download and save the script (banners.inc.php) to your UBBThreads includes folder.
2) Then configure the script by filling in the HTML for each banner listed. If you ever want to change/delete banners in the future you can easily edit the HTML code here.
3) Configure how many banners you wish to display on the page (0 to 12) from the entire pool of available ones.
4) Then simply include this code in your header/footer... Adjust the path as necessary if you are using it on a non-threads page.
<? include "$thispath/includes/banners.inc.php"; ?>
Disclaimer: Please backup every file that you intend to modify. If the modification modifies the database, it's a good idea to backup your database before doing so.
Note: If you modify your UBB.Threads code, you may be giving up your right for "official" support from Infopop.If you need official support, you'll need to restore unmodified files.
<br />// This section can be called via an include if you wish <br /><br />$image_html = array();<br /><br />// Insert the HTML code below for each image or banner in the pool (don't forget the \ before the ")<br />// You can also add individual ALT and TITLE tags if you wish<br /><br />$image_html[0] = "<a href=\"http://www.example1.com\"><img src=\"images/1.gif\" border=\"0\"></a>";<br />$image_html[1] = "<a href=\"http://www.example2.com\"><img src=\"images/2.jpg\" border=\"0\"></a>";<br />$image_html[2] = "<a href=\"http://www.example3.com\"><img src=\"images/3.png\" border=\"0\"></a>";<br />$image_html[3] = "<a href=\"http://www.example4.com\"><img src=\"images/4.gif\" border=\"0\"></a>";<br />$image_html[4] = "<a href=\"http://www.example5.com\"><img src=\"images/5.jpg\" border=\"0\"></a>";<br />$image_html[5] = "<a href=\"http://www.example6.com\"><img src=\"images/6.png\" border=\"0\"></a>";<br /><br />// Configure the number of unique images or banners to be displayed on the page<br />// It can be any number from 0-6 in the example given<br /><br />$number_of_images = 3; // <-- Configure<br /><br />$random = array_rand($image_html, $number_of_images);<br />?> <br />
into a file named banner.inc.php
where would I put the following line of code?Or am I going about this wrong? require ("includes/banner.inc.php");
Yes, I'm using 6.3 which is a li'l different. Although still use the same line I mentioned though.
I recommend using include() over require_once() since it is a non-critical file.
The former will merely give a warning upon failure while the latter will give a fatal error, which would be more understandable for the other listed includes.
// This section can be called via an include if you wish $image_html = array(); // Insert the HTML code below for each image or banner in the pool (don't forget the \ before the ") // You can also add individual ALT and TITLE tags if you wish $image_html[0] = ""; $image_html[1] = ""; $image_html[2] = ""; $image_html[3] = ""; $image_html[4] = ""; $image_html[5] = ""; // Configure the number of unique images or banners to be displayed on the page // It can be any number from 0-6 in the example given $number_of_images = 6; // <-- Configure $random = array_rand($image_html, $number_of_images); ?> Warning: Cannot modify header information - headers already sent by (output started at /usr/www/efs/ubbthreads/includes/banner.inc.php:10) in /usr/www/efs/ubbthreads/ubbt.inc.php on line 328
What did I do wrong here? That is showing where I would like my banners? I placed the code in my header insert
well one thing I forgot was this at the top of my banner.inc.php <?php It must be pretty important
so now I am getting just this
Warning: Cannot modify header information - headers already sent by (output started at /usr/www/efs/ubbthreads/includes/banner.inc.php:24) in /usr/www/efs/ubbthreads/ubbt.inc.php on line 328
I will try the the buffering now- *edit-still getting that last error even after inserting the buffer code*
Something else to try if going the include route...
Do the same thing I mentioned above with the output buffering but add those beginning and ending lines to ubbt.inc.php instead of the banner include. That *might* work.
Here's a follow-up to what you'll need to do if including everything in the header template (a little extra code req'd)...
Example (displaying 3 images from a pool of 3 possible):
<? //UBBTREMARK
$image_html = array();
// Insert the HTML code below for each image or banner in the pool (don't forget the \ before the ") // You can also add individual ALT and TITLE tags if you wish
ok I placed it in the ubbt_header.tmpl and it displays the images but does not do it randomly
If I assign this value $number_of_images = 3; // <-- Configure I get the same three images upon refreshing (the first three on the list I believe)
If I assign a value of $number_of_images = 1; // <-- Configure then nothing displays
Here is my ubbt_header.tmpl
Code
<!-- <? //UBBTREMARK --><br />// File Version 6.5<br />[:"green"]<br />$image_html = array();<br /><br />// Insert the HTML code below for each image or banner in the pool (don't forget the \ before the ")<br />// You can also add individual ALT and TITLE tags if you wish<br /><br />$image_html[0] = "<a href=\"http://www.bajema.com\"><img src=\"/ubbthreads/images/banners/bajbnr.jpg\" border=\"0\"></a>";<br />$image_html[1] = "<a href=\"http://melancholic.net\"><img src=\"/ubbthreads/images/banners/melancholicban.jpg\" border=\"0\"></a>";<br />$image_html[2] = "<a href=\"http://www.decayingmadness.com\"><img src=\"/ubbthreads/images/banners/decayingmadness.gif\" border=\"0\"></a>";<br />$image_html[3] = "<a href=\"http://www.vixenshop.com\"><img src=\"/ubbthreads/images/banners/vixshop.gif\" border=\"0\"></a>";<br />$image_html[4] = "<a href=\"http://www.giger.com/mainflash.htm\"><img src=\"/ubbthreads/images/banners/giger.jpg\" border=\"0\"></a>";<br />$image_html[5] = "<a href=\"http://www.pitchfork.de/page_en.php?\"><img src=\"/ubbthreads/images/banners/projectpitchfork.jpg\" border=\"0\"></a>";<br />$image_html[6] = "<a href=\"http://emeraldforestseattle.com\"><img src=\"/ubbthreads/images/happyhalloween.gif\" border=\"0\"></a>";<br /><br />// Configure the number of unique images or banners to be displayed on the page<br />// It can be any number from 0-6 in the example given<br /><br />$number_of_images = 1; // <-- Configure<br /><br />$random = array_rand($image_html, $number_of_images);<br /><br />[/]<br /><!-- echo <<<UBBTPRINT --><br /><!-- START OF header.tmpl TEMPLATE --><br /><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><html dir="{$ubbt_lang['READ_DIRECTION']}"><br /><head><br />$headerinsert<br />$refresh<br /><meta http-equiv="Content-Type" content="text/html; charset={$ubbt_lang['CHARSET']}" /><br /><link rel="stylesheet" href="$stylesheet" type="text/css" /><br /><link rel="shortcut icon" href="{$config['images']}/favicon.ico" /><br />$javascript<br /><title>{$config['title']}: $inputTitle</title><br /></head><br /><body><br /><!-- END OF header.tmpl TEMPLATE --><br /><!-- UBBTPRINT --><br /><!-- /* UBBTREMARK */ ?> --><br />
argh I posted that before I got to read your post.
Problem is I want to have the images displaying in the default header in the html include section so I have the first part in the ubbt_header.tmpl and this </center><center> <?php echo $image_html[$random[0]]; ?> <?php echo $image_html[$random[1]]; ?> <?php echo $image_html[$random[2]]; ?> <?php echo $image_html[$random[3]]; ?> <?php echo $image_html[$random[4]]; ?> <?php echo $image_html[$random[5]]; ?> <?php echo $image_html[$random[6]]; ?> </center> in the default header
Like I mentioned above, you need to convert the array into variables if posting into a template as opposed to echoing in a PHP script
So in your case it would look like this (I also gave a commented example in both sections for how to display 2 images instead of one in order to scale it up if needed)...
Code
<!-- <? //UBBTREMARK --> <br />// File Version 6.5 <br />[:"green"] <br />$image_html = array(); <br /> <br />// Insert the HTML code below for each image or banner in the pool (don't forget the \ before the ") <br />// You can also add individual ALT and TITLE tags if you wish <br /> <br />$image_html[0] = "<a href=\"http://www.bajema.com\"><img src=\"/ubbthreads/images/banners/bajbnr.jpg\" border=\"0\"></a>"; <br />$image_html[1] = "<a href=\"http://melancholic.net\"><img src=\"/ubbthreads/images/banners/melancholicban.jpg\" border=\"0\"></a>"; <br />$image_html[2] = "<a href=\"http://www.decayingmadness.com\"><img src=\"/ubbthreads/images/banners/decayingmadness.gif\" border=\"0\"></a>"; <br />$image_html[3] = "<a href=\"http://www.vixenshop.com\"><img src=\"/ubbthreads/images/banners/vixshop.gif\" border=\"0\"></a>"; <br />$image_html[4] = "<a href=\"http://www.giger.com/mainflash.htm\"><img src=\"/ubbthreads/images/banners/giger.jpg\" border=\"0\"></a>"; <br />$image_html[5] = "<a href=\"http://www.pitchfork.de/page_en.php?\"><img src=\"/ubbthreads/images/banners/projectpitchfork.jpg\" border=\"0\"></a>"; <br />$image_html[6] = "<a href=\"http://emeraldforestseattle.com\"><img src=\"/ubbthreads/images/happyhalloween.gif\" border=\"0\"></a>"; <br /> <br />// Configure the number of unique images or banners to be displayed on the page <br />// It can be any number from 0-6 in the example given <br /> <br />$number_of_images = 1; // <-- Configure <br /> <br />$random = array_rand($image_html, $number_of_images); <br /> <br />// Convert the array into variables for posting in a template <br />// The number of lines below is the *same number* specified by $number_of_images, in this case 1 <br />$image1 = $image_html[$random[0]]; <br />// $image2 = $image_html[$random[1]]; <-- This is how it would look if using 2 images in $number_of_images, and so on <br />[/] <br /><!-- echo <<<UBBTPRINT --> <br /><!-- START OF header.tmpl TEMPLATE --> <br /><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br /><html dir="{$ubbt_lang['READ_DIRECTION']}"> <br /><head> <br />$headerinsert <br />$refresh <br /><meta http-equiv="Content-Type" content="text/html; charset={$ubbt_lang['CHARSET']}" /> <br /><link rel="stylesheet" href="$stylesheet" type="text/css" /> <br /><link rel="shortcut icon" href="{$config['images']}/favicon.ico" /> <br />$javascript <br /><title>{$config['title']}: $inputTitle</title> <br /></head> <br /><body> <br /><!-- END OF header.tmpl TEMPLATE --> <br /><!-- UBBTPRINT --> <br /><!-- /* UBBTREMARK */ ?> --> <br />
Yeah I think you're gonna need to use an include for this because the ubbt_template.tmpl file and the generic header file aren't related to one another.
I'll keep plugging away at to see if I can come up some kind of with a workable solution, and if so, I will post in this thread.
Doing all of that did something funky to the table rows and bonked the layout of the page,didn't see a banner either. Its late so I will try again tomorrow-Thanks for the hard work Twisty
[]ChAoS said: Would it be hard to add in a variable that would rotate them without refreshing the page? Maybe something similar to this?
<?php // DynAds: Display an ad per period $StartDate = "15 January 2004" ; $PeriodHours = 24 ; $AdGroup = "NameOfTheAdGroup" ; $DispPosName = "NameForThisAdDisplayPosition" ; $ScriptUrl = "http://YourDomain/DynAdsInstallPath/ad.pl" ; // No editing beyond this line $PerCount = (int)((time() - strtotime($StartDate)) / ($PeriodHours*60*60)) ; $url = $ScriptUrl . "?pos=" . urlencode($DispPosName) . "&agn=" . urlencode($AdGroup) . "&dsp=html&sel=seq&ano=" . $PerCount ; @include($url) ; ?> <<<<gets ready to duck and run [/]
Ewww.
What you'll want to do is use client-side scripting for this task ie. Javascript as opposed to server-side scripting ie. PHP
So try this instead then. Add the following code to your generic template where the PHP include line is from my original mod which won't be needed anymore...
[]ChAoS said: So what do you think of the latter? Would it be usefull or just a matter of preference? [/]
Well it's just not the best way to go about it even if you could get it running perfectly. More inefficient compared to doing it client-side which is designed for this kind of thing :-)
PS - I added a tweak to the Javascript so that it no longer always starts cycling on the 1st image after a refresh, but rather chooses one randomly now and then cycles in order from there. This helps to ensure better coverage of the group.
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.