SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot webhost's Avatar
    Join Date
    May 2001
    Location
    Il
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Time Based Page Redirection

    We have a contact us page with online/open times and other information.

    We would like to also have a page that is somewhat different from the online page lets call it offline page.

    How would one use a php statement based on server time to have it automatically switch between pages?

  2. #2
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    use time() to get the time, and use an if statement to tell which page to display.
    Mike
    It's not who I am underneath, but what I do that defines me.

  3. #3
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    // the online time will be from 14 to 16:59 
    // taking minutes into consideration was 
    // more trouble
    /// so $onlineuntil should be realend - 1
    $onlinefrom 14// in hours
    $onlineuntil 16// in hours

    // $date holds the current HH
    $date date('H'time()); 

    if (
    $onlinefrom <= $date && $date <= $onlineuntil )
    {
       
    // display online
       // or forward using header('...');
    }

    else 
    {
       
    // display offline
       // or forward using header('...');
    }
    ?>

  4. #4
    SitePoint Zealot webhost's Avatar
    Join Date
    May 2001
    Location
    Il
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what we have in contact.php
    PHP Code:
    <?php // the online time will be from 14 to 16:59 
    // taking minutes into consideration was 
    // more trouble 
    /// so $onlineuntil should be realend - 1 
    $onlinefrom 12// in hours 
    $onlineuntil 18// in hours // $date holds the current HH 
    $date date('H'time()); if ( ! ($onlinefrom <= $date && $date <= $onlineuntil) ) {
        
    header("Location: [url]http://www.realwebhost.net/contact1.php[/url]");
    }
    ?>
    This what we have in contact1.php
    PHP Code:
    <?php // the online time will be from 14 to 16:59 
    // taking minutes into consideration was 
    // more trouble 
    /// so $onlineuntil should be realend - 1 
    $onlinefrom 18// in hours 
    $onlineuntil 12// in hours // $date holds the current HH 
    $date date('H'time()); if ($onlinefrom <= $date && $date <= $onlineuntil) {
        
    header("Location: [url]http://www.realwebhost.net/contact.php[/url]");
    }
    ?>
    But it does not work.

  5. #5
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    using 'H' with date will put a leading 0 for hours lower than 10.

    Try:

    PHP Code:
    <?php

    // the online time will be from 14 to 16:59
    // taking minutes into consideration was
    // more trouble
    /// so $onlineuntil should be realend - 1
    $onlinefrom 14// in hours
    $onlineuntil 16// in hours

    // $date holds the current HH
    $date date('G'time());

    if (
    $onlinefrom <= $date && $date <= $onlineuntil )
    {
       
    // display online
       // or forward using header('...');
    }

    else
    {
       
    // display offline
       // or forward using header('...');
    }
    ?>


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
  •