Results 1 to 7 of 7

Thread: Redirect Based On Time

  1. #1
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Redirect Based On Time

    Hi....I'm really desperate for a script that enables me to do this, so if anyone can help that would be great.

    I am writing a signup page that I only want users to access from 6.00pm-9.00pm on any day. The rest of the time I want users to be forwarded to a different page, telling them that they must signup between 6.00pm-9.00pm.

    Ideally, I would like to put the signup page on the same page as the php code which redirects the user, so that they can't access it out of hours.

    If you can help that would be great. If you can only think of a variation on this, thats great too!

    Thanks!

    PS: I did search, but nothing proved helpful/didn't work.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could try the following as a template. (Please note that this will go off of the server time, not the client's machine)

    PHP Code:
    <html>
    <head>
    <title>Sign-up</title>
    </head>
    <body>

    <?php
    $curTime 
    date('G',time()); //gets current hour [24 hour]

    if ($curTime <= "18" || $curTime >= "21") {
    /* if the time is less than 6pm (1800) or greater than 9pm (2100) display error */
    ?>

    You must signup in between 6:00pm and 9:00am (our server time).

    <?php

    }

    else {
    //else display signup form

    ?>

    <form action="register.php">
    <!--Your form data here-->
    </form>

    <?php
    }

    ?>

    </body>
    </html>
    I haven't tested this out, but it should work with little or no modification. Let me know if you need any more help.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    OK...so i tested it out on my home server and was able to play around with the date, and I found two mistakes in my previous code.

    replace the following:

    Code:
    $curTime = date('G',time()); //gets current hour [24 hour]
    
    if ($curTime <= "18" || $curTime >= "21") {
    with:

    Code:
    $curTime = date('Gi',time()); //gets current hour [24 hour]
    
    if ($curTime <= "1800" || $curTime >= "2100") {
    and that makes it work. Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much!

    I don't suppose you know how I can find my server time? It's still coming up with the message, rather than the form, but I think its because I've got the wrong time...(for the server...)
    Last edited by redtrain; 12-21-2006 at 09:00 PM.

  5. #5
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok....I think there's something wrong with the script....I've opened the time from 0000 to 1259 and it still brings up the message.

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    if you want to find out the server's time, make a PHP script (let's call it curTime.php). In the script, place the following code:

    PHP Code:
    <?php

    echo 'Current time (12 hour): '.date("h:i:s"time()).'<BR>';

    echo 
    'Current time (24 hour): '.date("H:i:s"time());
    ?>
    Both of those will tell you the current server time in hours:minutes:seconds in 12/24 hour formats. If this doesn't help, let me know and I'll see what else I could do.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    For a little bit simpler you could just use the time based header redirect:

    PHP Code:
    <?php
    if(date("H")<8)
    header("Location: http://www.yoursite.com/path/to/page.php")
    ?>
    You just place this on the VERY top of the page (before the <html> or any other space, character etc. on the non-form page. and fill in the Location URI to the form/sign up page.

    Note the "H" is php for hour, so this code exactly will redirect between 12 midnight and 8 a.m. server time.

    Or for more advanced options see this thread with particular attention to reply #5 and #6
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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
  •