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
Link to comment
Share on other sites

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...,
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.