Jump to content

[SOLVED] Suggestions for randomly changing image?


everettcomstock

Recommended Posts

Hi Everyone,
      I am trying to create a site where the main header and footer images will show random images from a "theme" folder. The problem that I am running into is that once the "Theme" images load, I would like for them to then stay static while other images (like my random photo from my photo gallery and album cover from my radio station) are able to "refresh".
      Would you recommend that I use sessions or maybe pass a variable that sets the "theme." I am not looking for specific scripting help, mainly just ideas of what you think would work the best, and what would be the "cleanest" method for the script. Sorry for all of the apostrophes! Thanks for all of your help!

Everett
if its a different picture  each time the page loads, then you would name the imges using an integar eg "image1, image2, image 3 etc." and then call it from a randomly generated variable

$img_num = rand(1, 3);

<img src------/themes/image$img_num.gif>


hope that helps...,
If I understand your problem correctly, I would suggest setting either a session variable or a cookie.  Sessions have a short lifespan, but are safe to use because they can not be blocked.  Cookies last longer, but they can be blocked at the browser level.  If you want to have a different theme every time someone comes to your site, I recommend setting a variable in the session to indicate which theme to use.  If you don't find it in the session, choose a random theme and set the variable.  This way you can have a consistent appearance for your site for the entire life of the session.  The only problem that you might have is when someone walks away from their computer for a while and the session expires.  They would then see a change in the theme of your site when the next random theme is chosen.  Hope this helps.

Chris

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.