PDA

View Full Version : Random Script


Dean C
01-03-2003, 01:11 PM
///////// Start Random Banner Hack /////////////

//Define Variables //
$banner1="banner1.gif";
$banner2="banner2.gif";
$numbanners = 2;

// Generate ranodomness
srand(microtime() * 1000000);
$num = rand(1,$numbanners);

// do switch
switch($num) {
case 1 : $makebanner="$banner1"; break;
case 2 : $makebanner="$banner2"; break;
}

//output banner
$banner = "<img src=\"$makebanner\" border=\"0\">";

////////// End Random banner Hack///////////////


I put that code in global.php and then put $banner in my footer but it didn't work :(

Whats the problem here :)?

Regards

- miSt

DrkFusion
01-03-2003, 04:43 PM
Try using a script Velocd uploaded
https://vborg.vbsupport.ru/attachment.php?s=&postid=276522

Regards

Dean C
01-03-2003, 06:03 PM
The idea was i did this on my own :)

- miSt

DrkFusion
01-03-2003, 07:50 PM
aH, you should of said so from the begining :-p

Dean C
01-03-2003, 08:26 PM
Yes so has anyone a solution to this - this is obviously more than just whats there :)

- miSt

Logik
01-03-2003, 08:48 PM
Im sorry but that seems right.

Dean C
01-03-2003, 09:03 PM
Yes it is right - no parse errors or anything but it simple does not pull the image with the $banner variable for some reason :(

colicab-d
01-03-2003, 09:32 PM
hmm i dont know much php but i would guess maybe something to do with the do switch ? or the way your setting up the last $banner variable ? i dunno, thats what i would say but my knowledge lies in truebasic or yabasic not php :p

NTLDR
01-03-2003, 09:38 PM
Try:


///////// Start Random Banner Hack /////////////

//Define Variables //
$banner1="banner1.gif";
$banner2="banner2.gif";
$numbanners = 2;

// Generate ranodomness
$num = rand(1,$numbanners);

//output banner
$banner = "<img src=\"$banner[$num]\" border=\"0\" alt=\"\" />";

////////// End Random banner Hack///////////////

Dean C
01-04-2003, 11:38 AM
No parse erros with that code but again i hae $banner in my footer and it's not showing the image :(

- miSt

DrkFusion
01-04-2003, 02:39 PM
Where does banner1.gif and banner2.gif locate?
Can you show us the site at which it is being used?
For Ex: if it is being used on index.php page of your forums, you may of not uploaded the banners to the forum root, you may of uploaded to perhaps a banners directory.

Just double check:p

Dean C
01-04-2003, 05:52 PM
I'mt testing it locally - code is in global.php (also tested in index.php)

And the banners are in the root directory

I'm sure it has something to do with inserting it in the 'footer' template because online user stuff is defined in index.php yet you have to use a hack to put the code in the header :p

- miSt

NTLDR
01-04-2003, 06:51 PM
You need to make sure that the code is placed before the footer template is eval'ed in global.php, so either before global.php is required, in the phpinclude template, or above the footer eval statement in global.php

Dean C
01-04-2003, 07:35 PM
Ahh i'll try putting it in the 'footer' template... brb

Dean C
01-04-2003, 08:57 PM
Ahhh i got it working - thanks NTDLR - that did the trick :)

- miSt

Dean C
01-06-2003, 03:56 PM
Ok next problem


//Define Variables //
$pathtoyourimagesfolder="http://localhost/forums/images";
$banner1="vbulletin_logo.gif";
$banner2="banner2.gif";
$numbanners = 2;

// Generate ranodomness
$num = rand(1,$numbanners);

//output banner
$banner = "<img src=\"{imagesfolder}/$banner[$num]\" border=\"0\" alt=\"\" />";


I use that code and the $banner variable outputs an image but it doesn't fetch it if you know what i mean...

When i click properties for the image the path is:

http://localhost/forums/images/

- miSt

NTLDR
01-06-2003, 06:21 PM
Use $banner$num, thats my fault, a slight error in the code I posted ;)