everettcomstock Posted January 8, 2007 Share Posted January 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 8, 2007 Share Posted January 8, 2007 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..., Quote Link to comment Share on other sites More sharing options...
matto Posted January 8, 2007 Share Posted January 8, 2007 not sure if this is what you mean$random_images = array("image1.gif","image2.gif","image3.gif","image4.gif");shuffle($random_images);echo "<img src=\" . $random_images[0] . "\">"; Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 8, 2007 Share Posted January 8, 2007 that would do the same thing, but ,mine is simpler to write and to use Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted January 8, 2007 Share Posted January 8, 2007 you could also store as many as you wanted in a database and use random number to call them from the db by an id... :P Quote Link to comment Share on other sites More sharing options...
cshireman Posted January 8, 2007 Share Posted January 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
matto Posted January 8, 2007 Share Posted January 8, 2007 What PC Nerd is saying is true, but this will restrict you to a specific file naming convention where as the version I have supplied will allow for any file name to be added to the array. ;) Quote Link to comment Share on other sites More sharing options...
everettcomstock Posted January 8, 2007 Author Share Posted January 8, 2007 Thanks for all of the help guys! I now know what I need to do.Everett Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.