Results 1 to 9 of 9

Thread: Redirect Based On Date AND Time

  1. #1
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Redirect Based On Date AND Time

    i want a code to redirect someone one different days and times when events are happening for example some times it would be a saturday at 12.15-5.15 i want them redirected and other times it may also be a wednesday night about 7.15-10.15. i want to be able to program these times in like says all the different saturdays wednesdys and sundays upto the end of each month so i dont have to keep modifying it, also after the 5.15 in my 1st example i would like it to not redirect just to stay on the page like normal. thanks zack

  2. #2
    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

    Not sure how much this will help... but it works for me:

    Code:
    <?php
    if(date("H")<8)
    header("location: /page.php")
    ?>
    Obvisouly this is just a time redirect, but it does work with all php based time stamps, so all you need to do is throw in a couple if else statements with the date codes you need, and viola!

    If you need more detailed ones I am sure Twey will be around soon
    {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

  3. #3
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks but does anyone have a date code and if so would i just put

    date code

    time code?

    thanks

  4. #4
    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

    You can find date codes HERE

    An example of what you would need is this: (untested)

    Code:
    <?php
    $a = date('G');
    if($a < 6) 
    header("location: /page.php")
    else if($a < 12) 
    header("location: /page2.php")
    else if($a < 18)
    header("location: /page3.php")
    else header("location: /page4.php");
    ?>
    Not sure exactly how to code that.. TWEY!!!!! Help out?? LOL
    {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

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Twey's had no internet for far too long, and had to resort to Lynx for the last couple of days. I hate wireless.
    it would be a saturday at 12.15-5.15 i want them redirected and other times it may also be a wednesday night about 7.15-10.15.
    This just involves a little arithmetic.
    Try:
    PHP Code:
    <?php
    $hour 
    date('G');
    $minute date('i');
    $day date('w');
    $m $hour 60 $minute// Minutes since midnight.
    if(
      
    $day == // Saturday...
      
    && $m >= 735 // ... after 12:15...
      
    && $m <= 1035 // ... but before 17:15...
    header("Location: saturdayafternoon.php");
    else if(
      
    $day == // Wednesday...
      
    && $m >= 1155 // ... after 19:15...
      
    && $m <= 1335 // ... but before 22:15...
    header("Location: wednesdaynight.php");
    ?>
    Untested. Beware: your server may be in a different timezone to you...
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    header("Location: saturdayafternoon.php");
    It should be noted that the Location header requires an absolute URI (http://www.example.com/path/to/resource), not a relative one.

    The documentation for the header function demonstrates how to do this dynamically, if necessary.

    Mike

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Whoops. You corrected me on this before. Sorry, it slipped my mind.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Additional help

    Supposed I wanted a particular page to load the first week of every month, but then for the remainder of the month, a different page? Any thoughts?
    Thanks

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This discussion is five years old. Start a new one if you have a new question.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •