PHP Redirect Code

Discussion in 'PHP' started by livedomainsearch, Oct 14, 2008.

  1. #1
    Hi, I am trying to locate a php redirect code that allows you to control the time in how long it will take before it redirects the page to the other. If anyone can help, please let know!. Thank you!
     
    livedomainsearch, Oct 14, 2008 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    PHP redirects are instantaneous. If you want to use a redirect with a time delay you should output a HTML redirect page from your php.
     
    deathshadow, Oct 14, 2008 IP
  3. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #3
    function redirect($time, $topage)
    {
    echo "<meta http-equiv=\"refresh\" content=\"{$time}; url={$topage}\" /> ";
    }

    redirect(3,'location.php');
     
    bartolay13, Oct 14, 2008 IP
  4. blackthought286

    blackthought286 Well-Known Member

    Messages:
    334
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    you could use the sleep function such as

    
    <?php
      goNow();
    ?>
    
    <?php
      function goNow(){
        //will wait 5 seconds 
        sleep(5);
        header('Location: http://www.google.com');
      }
    ?>
    
    
    PHP:
     
    blackthought286, Oct 14, 2008 IP
  5. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #5
    +1 to blackthought, a php version of delaying redirect
     
    bartolay13, Oct 14, 2008 IP
  6. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #6
    This is the delayed redirection

    header('refresh:3; url=http://www.google.com');
    PHP:
    3 seconds delay
     
    ads2help, Oct 14, 2008 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #7
    -1,000,000 for hanging a server process and a connection while executing nothing
     
    deathshadow, Oct 15, 2008 IP
  8. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #8
    not the fine english way to clog the server this way.
    a meta refresh is the right way to do it.
     
    happpy, Oct 15, 2008 IP
  9. livedomainsearch

    livedomainsearch Peon

    Messages:
    111
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thank you ALL!
     
    livedomainsearch, Oct 16, 2008 IP
  10. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #10
    that's nice. and yes, sleep is NOT a good idea.
     
    dimitar christoff, Oct 16, 2008 IP