Log in

View Full Version : Random image backround?


bhxtyrant
08-08-2006, 11:47 PM
Hey guys,
I have a bit of a dilema here.I am currently searching for a random image script that makes the image change each time the page is refreshed/reloaded.I found a few that work fine but thats were the problem comes in.I am attempting to use this to make two images on my forum banner change at the same time so they match each other on each refresh but i can not find a script thaat does this.Due to my limited knowledge of PHP and javascript i can not make my own so i was hoping someone may be able to help me.

Im not sure exactly what info is needed so please let me know if you need anything and i will provide it.Thanks.

lightwave
08-09-2006, 03:10 AM
Hello, I have a random image in my website but it can work for background

here is the code:

$random_bg=rand(1,23);
ECHO "<BODY STYLE=\"BACKGROUND-IMAGE:URL(http://yourwebsite.com/background_{$random_bg}.jpg);\">";


Basically, you name all your backgrounds

background_1.jpg
background_2.jpg


change the 23 in rand(1,23); to wahtever max images you have. if you have 10, then chagne it to rand(1,10);

then u just change the URL.

bhxtyrant
08-09-2006, 10:11 AM
thanks lightwave,i will give it a try,do you know if this will work for two images?
http://img49.imageshack.us/img49/4616/untitled2zl1.th.gif (http://img49.imageshack.us/my.php?image=untitled2zl1.gif)

This image shows the part of my page with the images i want to change,so maybe that will help answer this question a bit better.The only problem is i dont need a random backround script.I more so want the images to change in a certain order each time the page is refreshed.for example first refresh would make the top image number 1 and bottom image number 1 show,then it would go to top image number 2,bottom image number 2,and so on.

pyro.699
08-09-2006, 07:53 PM
What i would do in my case, is put all of the image files in an array

$arr = array('image1.jpg', 'image2.jpg')

Then i would call it by going

echo '<img src="./'.array_rand($arr).'"/>';

bhxtyrant
08-09-2006, 08:05 PM
would this work for backround images though?Sorry for the noob Q's i dont know very much PHP.

pyro.699
08-10-2006, 01:09 AM
yup, any images :)

bhxtyrant
08-15-2006, 05:06 PM
Hey guys sorry for the long overdue bump of this topic.I remebered something after reading up a bit that i needed to check on reguarding the above php array idea.I recall reading somewhere on this forum that php scripts will not work inside of the vbulliten templates so doesnt this mean that the array would not work as i want to use it in my vB header tamplate?

pyro.699
08-15-2006, 06:16 PM
you have to call the template dont you?

$image = array_rand($arr);
^in your php file

and in your template call $image

<body background-image="$image">
^ in your template

I think my html is wrong, but you get the idea