Display different picture based on time (and day?)

Discussion in 'PHP' started by waffles, Jun 19, 2006.

  1. #1
    I'm not even sure where to begin on this one, so I'll just tell you what I'm looking for.

    I would like to have two images on my radio page to indicate on air or off air status. But, I would like the pictures changed automatically so that if someone comes to the page the correct picture will be up without my having to manually change it.

    In the most perfect world I would have this happen just for my show, which will be 2 hours one day a week.

    If that's too much of a pain I'd like it to have the "On Air" image from 4-midnight everyday and "Off Air" the other times.
     
    waffles, Jun 19, 2006 IP
  2. TheGuy

    TheGuy Peon

    Messages:
    138
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What is your platform? Are you using PHP/JSP/ASP? or plain old HTML? This is very easy to do using PHP or Javascript. Try tweaking http://www.globalrph.com/davescripts/greeting.htm for your needs. If you want to handle it with PHP, it will be something similar to this javascript.
     
    TheGuy, Jun 19, 2006 IP
  3. waffles

    waffles Peon

    Messages:
    87
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    PHP would probably be preferable since individual users can't turn it off, that I know of anyway.
     
    waffles, Jun 19, 2006 IP
  4. TheGuy

    TheGuy Peon

    Messages:
    138
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It's pretty simple.
    Note: The following code has not been tested, it may or may not work.

    
    $start_hour = 12; // Noon
    $end_hour = 14; // 2 @ Afternoon
    $hour_now = date("H");
    if($hour_now >= $start_hour || $hour_now <= $end_hour)
    {
    echo "<img src=\"online.gif\">";
    }
    else
    {
    echo "<img src=\"offline.gif\">";
    }
    
    PHP:
     
    TheGuy, Jun 19, 2006 IP
  5. waffles

    waffles Peon

    Messages:
    87
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    How can I force it to use a certain timezone? I'd hate for someone to see the On Air image because their computer clock says the correct time.
     
    waffles, Jun 19, 2006 IP
  6. TheGuy

    TheGuy Peon

    Messages:
    138
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The time here, would be your server's time ad not the time on User's machine.
     
    TheGuy, Jun 19, 2006 IP
  7. waffles

    waffles Peon

    Messages:
    87
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sweet. Got it all nice and done now.
     
    waffles, Jun 19, 2006 IP