SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast acidfish's Avatar
    Join Date
    Mar 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking Best method 2 Change bckground header img randomly?

    What is the best method to get a background image header/banner/title-bar to automatically and randomly change each time the page is opened. I read a PHP book that changed the image seasonally. What would be the best: flash, java, actionscript. or the php or anything else? I'm willing to explore and learn thx in advance for any ideas.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,897
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    I would use PHP for this. Flash and the likes are way to heavy tools to solve this relatively simple problem.

    Assuming you have image1.jpg, image2.jpg, ... imageN.jpg, a simple snippet like this will do:

    PHP Code:
    <img src="image<?php echo rand(110); ?>.jpg" alt="" />
    Or you could put all images in an array and pick one at random.

    (code assumes you have 10 images)
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Addict AtSea webdesign's Avatar
    Join Date
    May 2010
    Location
    Newark, Delaware
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the two best choices would be javascript and php. Javascript could be used on html pages where as php has to be used on a .php file.

    In other words you have to make sure your server supports php. Otherwise do it with a simple javascript random script.

  4. #4
    SitePoint Evangelist Ed Seedhouse's Avatar
    Join Date
    Aug 2006
    Location
    Victoria, B.C. Canada
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, just to be picky, I will point out that none of these techniques produce a "random" image, merely a "pseudo random" one, since no computer algorithm can produce a truly random sequence on it's own.
    Ed Seedhouse

  5. #5
    SitePoint Enthusiast acidfish's Avatar
    Join Date
    Mar 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    PHP looks tops so far, I got a book on that 1 . The appeal of JavaScript is being on the page. Atsea can you direct me toward working examples or code to have a look at the mechanics?

    Expanding the idea. Can you mix-up a "shtml" site with PHP added onto a working shtml site? Out of curiosity... interest??? Thx for the help above and any to follow bellow

  6. #6
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    As far as I remember you cannot mix both; SHTML with PHP in that sense, i.e. on the same page.

  7. #7
    SitePoint Addict AtSea webdesign's Avatar
    Join Date
    May 2010
    Location
    Newark, Delaware
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Acid, google javascript random image. There are a ton of examples out there.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •