Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: redirect once at certain time?

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

    Talking redirect once at certain time?

    How would i create a script that would take a user to a page at a certain time and wouldn't take them there again until the next day at the same time?

    Thanks

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

    Default

    May need some modification, and it is not tested.

    Code:
    <?php
    
    $redirect_Start = "1400"; //don't redirect before 2pm
    $redirect_End = "1500"; //don't redirect after 3pm
    
    $redirect_To = "redirect.php"; //where to redirect to
    
    if (date('Gi') >= $redirect_Start && date('Gi') <= $redirect_End) {
    
      header('Location: '.$redirect_To);
    }
    
    else {
    //whatever you want
    }
    ?>
    Hope this helps.

    //EDIT: new addition to code is not tested Modifications are in red. Let me know if it doesn't and I will work on fixing it.
    Last edited by thetestingsite; 04-13-2007 at 11:40 PM.
    "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
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That would work, I think, but why would you redirect at only exactly 2pm?
    That would only do it for that specific time. I guess it might do the whole hour, but I'm not sure.
    I'd think a range would be better, or just "after 2pm", etc.
    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

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

    Default

    Yea, that script will only redirect a user at 2pm (not 2:01 or 1:59, but 2pm on the dot). I was working on adding to it, but went to lunch and this slipped my mind. Thanks for bringing this back up, djr33.
    "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

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

    Default

    This should work... change as needed--
    PHP Code:
    <?php

    $redirect_Time 
    "1400"//redirect at 2pm
    $redirect_Flex "30"//.5hr flexiblity (1:30-2:30)
    $redirect_To "redirect.php"//where to redirect to

    if (date('Gi') >= $redirect_Time-$redirect_Flex && date('Gi') <= $redirect_Time+$redirect_Flex) {

      
    header('Location: '.$redirect_To);
    }

    else {
    //whatever you want
    }
    ?>
    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

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

    Default

    i have a problem with "tts" code:
    Code:
    <?php
    
    $redirect_Start = "1300"; //don't redirect before 8pm
    $redirect_End = "1400"; don't redirect after 9pm
    
    $redirect_To = "javascript:buildtimeP()"; //where to redirect to
    
    if (date('Gi') >= $redirect_Start && date('Gi') <= $redirect_End) {
    
      header('Location: '.$redirect_To);
    }
    
    else {
    //whatever you want
    }
    ?>
    it says there is a problem with the:
    Code:
    if (date('Gi') >= $redirect_Start && date('Gi') <= $redirect_End) {
    part.

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

    Default

    The only thing I can see with the code you posted is an uncommented line:

    Code:
    <?php
    
    $redirect_Start = "1300"; //don't redirect before 8pm
    $redirect_End = "1400"; //don't redirect after 9pm
    
    $redirect_To = "javascript:buildtimeP()"; //where to redirect to
    
    if (date('Gi') >= $redirect_Start && date('Gi') <= $redirect_End) {
    
      header('Location: '.$redirect_To);
    }
    
    else {
    //whatever you want
    }
    ?>
    The part in red is what needs to be added, other than that the code should work fine.
    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

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

    Default

    I don't believe you can redirect to a javascript: pseudo-URL in a Location header.
    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!

  9. #9
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Yes, I think that's only an anchor property... I'll test it though.
    - Mike

  10. #10
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Hmm. Type this into your url:
    Code:
    javascript:alert(typeof window);
    Seems to work.
    - Mike

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
  •