View Full Version : Ad rotating
Decode
30-11-2007, 04:41 PM
K, ive got 4 pages.
ads/ad1.html
ads/ad2.html
ads/ad3.html
ads/ad4.html
they all have a simple html code like <a href="url" target="_blank"><img src="url"></a>
I want to use php include to include 1 of them randomly each time on my homepage. How would i do that?
Frog!
30-11-2007, 04:45 PM
<?php
$rand = rand(1, 4);
if($rand == 1)
{
include("ads/ad1.html");
}
if($rand == 2)
{
include("ads/ad2.html");
}
if($rand == 3)
{
include("ads/ad3.html");
}
if($rand == 4)
{
include("ads/ad4.html");
}
?>Hope it helps.
Decode
30-11-2007, 04:47 PM
Thanks Frog!
+Rep
LegendOfNoob
30-11-2007, 04:49 PM
One Second Here Finding it
This is a code invent posted on clubhabbo its a random link generator
there should be a code simliar or this code could be edited to show the pages instead
<?php
// stuff to poke
$stuff[ 0 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME </a>';
$stuff[ 1 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 1</a>';
$stuff[ 2 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 2</a>';
$stuff[ 3 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 3</a>';
$stuff[ 4 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 4</a>';
$stuff[ 5 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 5</a>';
$stuff[ 6 ] = '<a href="http://www.habbo.co.uk/home/NAME">NAME 6</a>';
$stuff[ 7 ] = '<img src="http://www.habbo.co.uk/habbo-imaging/avatarimage?user=NAME&action=wve&frame=3&direction =4&head_direction=4&gesture=sml&img_format=gif">';
$stuff[ 8 ] = '<img src="http://www.habbo.co.uk/habbo-imaging/avatarimage?user=NAME&action=wve&frame=3&direction =4&head_direction=4&gesture=sml&img_format=gif"> 2';
//Dont poke this, it'll work, just change values above and add/remove from em
$display=rand(0, sizeof($stuff)-1);
echo $stuff[$display];
?>
?>
Oringinal Plot of Reason for Invent's Code:
<?php
//SET BANNER URLS.
$banner1 = "banner1_url_here.gif";
$banner2 = "banner2_url_here.gif";
$banner3 = "banner3_url_here.gif";
$banner4 = "banner4_url_here.gif";
//FINISH SETTING BANNER URLS.
$rand_func = rand(1,4); //This code will make the random banner easier.
if($rand_func == '1') {
echo("<img src=\"$banner1\">"); //Prints the banner image to the page if the banner number to show is 1.
}
if($rand_func == '2') {
echo("<img src=\"$banner2\">"); //Prints the banner image to the page if the banner number to show is 2.
}
if($rand_func == '3') {
echo("<img src=\"$banner3\">"); //Prints the banner image to the page if the banner number to show is 3.
}
if($rand_func == '4') {
echo("<img src=\"$banner4\">"); //Prints the banner image to the page if the banner number to show is 4.
}
?>
so actually if its ad banners it will be quite easier as a image
One Second Here Finding it
This is a code invent posted on clubhabbo its a random link generator
there should be a code simliar or this code could be edited to show the pages instead
Oringinal Plot of Reason for Invent's Code:
so actually if its ad banners it will be quite easier as a image
I'd go for a solution like this rather than the technique you are using above, as it's all in the one file, rather than having a file for each ad :)
RichardKnox
30-11-2007, 08:35 PM
Or to shorten the other guys code:
<?php
$rand = rand(1, 4);
include("ads/ad".$rand."");
?>
Florx
30-11-2007, 09:35 PM
Or use javascript. (nicked from clubhabbo)
<script type="text/javascript">
var preloaded = new Array();
function preloadImages() {
for (var i = 0; i < arguments.length; i++){
preloaded[i] = document.createElement('img');
preloaded[i].setAttribute('src',arguments[i]);
};
};
preloadImages(
'/images/sitebanners/council.gif',
'/images/sitebanners/voteofficial.gif'
);
var links = new Array(
'/news/show_news.php?subaction=showfull&id=1196059919&archive=&start_from=&ucat=25&',
'/news/show_news.php?subaction=showfull&id=1195081110&archive=&start_from=&ucat=25&'
);
var text = new Array(
'<b>The ClubHabbo Council</b> has returned, and we are hiring new Council Members!',
'Official UK Fansite voting is open, and ClubHabbo needs <b>YOUR</b> vote!'
);
var curOffset = 1;
window.onload=function() {
document.getElementById('randLink').href = links[0];
document.getElementById('randImage').src = preloaded[0].src;
document.getElementById('randText').innerHTML = text[0];
setInterval(
function() {
document.getElementById('randLink').href = links[curOffset];
document.getElementById('randImage').src = preloaded[curOffset].src;
document.getElementById('randText').innerHTML = text[curOffset];
curOffset = (curOffset >= preloaded.length-1) ? 0 : curOffset + 1;
}, 10000);
};
</script>
In the head tag.
In the body tag:
<a id="randLink" href="#"><img src="" border="0" id="randImage"></a></div>
<div id="randText">
</div>
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.