• Trying to write part of a page that would display a streaming player when we are on the air 5a-10a M-F and display something else when we aren’t on the air.

    Here’s what I have right now, but it’s not working. I’m pretty new at PHP. Thanks!

    <html>
     <head>
      <title>streaming</title>
     </head>
     <body>
    
    <?php
    
    //Get the current hour
    $current_time = date(G);
    //Get the current day
    $current_day = date(l);
    
    //On Air
    if ($current_day == "Saturday" or $current_day == "Sunday" or ($current_time <= 5 && $current_time >= 10)) {
    echo "We’re live Monday – Friday mornings. Check back then.";
    }
    
    // Display player
    else {
    echo "<a href="linktoplayer.html"><img src=http://www.psdgraphics.com/wp-content/uploads/2009/09/play.jpg></a>";
    }
    
    ?>
    
    </body>
    </html>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. Or better still – use the pastebin. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

Viewing 1 replies (of 1 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this:

    <?php
    // Set your timezone
    // List of Supported Timezones - http://php.net/manual/en/timezones.php
    date_default_timezone_set('Europe/Amsterdam');
    
    //Get the current hour
    $current_time = date('G');
    //echo $current_time;
    
    //Get the current day 0 (for Sunday) through 6 (for Saturday)
    $current_day = date('w');
    //echo $current_day;
    
    //On Air - Display player
    if ((($current_day >= 1) && ($current_day <= 5)) &&
        (($current_time >= 5) && ($current_time <= 10))) {
    echo '<a href="linktoplayer.html"><img src=http://www.psdgraphics.com/wp-content/uploads/2009/09/play.jpg></a>';
    } else {
    echo "We’re live Monday – Friday mornings. Check back then.";
    }
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘PHP help’ is closed to new replies.