Display image after 9PM

Discussion in 'PHP' started by Lloyd Dear, Mar 5, 2013.

  1. #1
    Hi all,

    I run my own online radio station and would like to display an image on my website ONLY between 9PM - 4AM, and before this time I wish nothing to be displayed.

    Please could anyone advise me of the php script that would allow me to do this.

    Thanks in advance :)
     
    Solved! View solution.
    Last edited: Mar 5, 2013
    Lloyd Dear, Mar 5, 2013 IP
  2. #2
    Hacked this quickly together

    <?php
     
        $showimage = date(H);  
        if ($showimage >= 21 || $showimage <= 03){
        echo "<img src='path/to/image.png' >";
        } 
         
    ?>
    Code (markup):
    Well, this'll display an image between 21:00 (9PM) and 03:59 (AM)


    Hope this works
     
    GMF, Mar 5, 2013 IP
  3. Garkoni

    Garkoni Active Member

    Messages:
    213
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    You need to remember that the server timezone may differ from your visitors', so you'll need to take care of the locale.
     
    Garkoni, Mar 5, 2013 IP
  4. Lloyd Dear

    Lloyd Dear Greenhorn

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    Hi,

    Thanks for you help GMF! Works like a charm, i have set it to 5PM and 6PM to test it and it all works :)

    Garkoni: I did think about this and in the image i will be displaying i will show GMT (my location) so listeners know :) thanks also
     
    Lloyd Dear, Mar 5, 2013 IP