Need Help Creating Delay Between Redirect.

Discussion in 'PHP' started by BrettOwnz, Mar 5, 2009.

  1. #1
    Hey there everybody,

    I'm new to PHP, but i have a mediocre knowledge. I am coding a simple login module to learn more of the functions etc. Its going very well, everything is set up just like i would want it, except for one thing.. I have messages on each page before they redirect.. Such as, "you didn't enter a password. please try again." but, you cannot read them for more than a half second, because the page changes too fast. I know i could use the sleep() function to make a delay between the pages, but it wasn't working out for me too well, and seemed to be useless. Does anyone else have ideas? Thanks.. And i know, you might say "search google" but i already have, and found absolutely nothing that worked..

    Thanks again everyone!
     
    BrettOwnz, Mar 5, 2009 IP
  2. Shoro

    Shoro Peon

    Messages:
    143
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It sounds like you're using a meta refresh to redirect, use something like this:

    
    <meta http-equiv="refresh" content="4;URL=redirectlocation.html"/>
    
    Code (markup):
    Where you change "4" to however many seconds you want to delay the redirect by.
     
    Shoro, Mar 5, 2009 IP
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    <?php
    header('refresh=5; URL=where.com');
    ?>
    
    PHP:
    change the 5 seconds to suit your need
     
    ads2help, Mar 5, 2009 IP
  4. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Better to try:
    header('Refresh: 5; url=http://www.example.com/');
    PHP:
     
    SmallPotatoes, Mar 5, 2009 IP
  5. BrettOwnz

    BrettOwnz Member

    Messages:
    286
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #5
    Thanks for the ideas.. but none of them will work in my situation, because the code i am doing is before the header tag (thats where meta goes) and i can't resend the headers. I am going to try to use the sessions method..

    Thanks Again!
     
    BrettOwnz, Mar 6, 2009 IP
  6. jackio

    jackio Banned

    Messages:
    490
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I never tried it before, but you have a sleep() function in PHP, maybe combining that with header() or javascript window.location you can achieve what you need.
     
    jackio, Mar 7, 2009 IP
  7. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #7
    It's a typo. It should be refresh: 5 ; URL=...

    Thanks.

    No, you can do the redirection at anytime. Just put ob_start(); at the most top of the file (before any output, usually after the <?php)

    - ads2help
     
    ads2help, Mar 7, 2009 IP
  8. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #8
    Do a fast redirect to a inbetween redirect page that will display your message passing any information to that inbetween page you need. In the header meta portion of that inbetween page you put

    <meta http-equiv="refresh" content="4;URL=http://site.com/PLACETOREDIRECTTHEM.html"/>

    Have you seen the page that is shown to you when logging into digitalpoint.com forums? It says you will be redirected after a short period of time. This is how I am explaining to do it. With that header meta data it will wait X amount of seconds before going to the next page.
     
    exodus, Mar 7, 2009 IP
  9. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #9
    
    <?php
    sleep(5);
    header("Location: http://www.example.com/");
    ?>
    
    PHP:
     
    Kaizoku, Mar 7, 2009 IP
  10. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #10
    That's a waste of server resources, since you can easily get the client to do the waiting instead.
     
    SmallPotatoes, Mar 7, 2009 IP
  11. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #11
    FYI sleep() does not waste resources <_<
     
    Kaizoku, Mar 7, 2009 IP
  12. BrettOwnz

    BrettOwnz Member

    Messages:
    286
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #12
    Thanks for the suggestions everyone, will try once i fix up another part of my code.. ;)
     
    BrettOwnz, Mar 7, 2009 IP
  13. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Yes it does. It holds open an Apache child process and/or connection slot.
     
    SmallPotatoes, Mar 8, 2009 IP
  14. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #14
    but it doesn't use any cpu or memory. No need to worry, worse can happen is process gets defunct.
     
    Kaizoku, Mar 8, 2009 IP
  15. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #15
    An open Apache child process uses 8M+ of real RAM. That adds up. If you'd had to manage servers that are in heavy use you'd feel my pain on seeing that sleep() call.
     
    SmallPotatoes, Mar 8, 2009 IP