PHP Redirect Pause

前端 未结 8 1204
北荒
北荒 2020-12-28 19:08

How do I pause a page for a certain amount of seconds before redirecting the user to another HTML/PHP page using PHP?

相关标签:
8条回答
  • 2020-12-28 19:46

    The other 2 options are a Javascript redirect using setTimeout() or a meta refresh tag with a timeout.

    0 讨论(0)
  • 2020-12-28 19:49

    Low-tech solution requiring no Javascript or even PHP:

    <html>
    <head>
        <title>Redirecting...</title>
        <meta http-equiv="refresh" 
    content="10;URL=http://www.newsite.com">
    </head>
    <body>
        You are being automatically redirected to a new location.<br />
        If your browser does not redirect you in 10 seconds, or you do
        not wish to wait, <a href="http://www.newsite.com">click here</a>. 
    </body>
    </html>
    

    The advantage of this solution over using the "Location:" header is that you don't need to pause the script execution, which will appear to the user as if the server is busy or their connection has hung.

    This solution also gives the user the option of proceeding to the new page immediately rather than having to wait x number of seconds while their browser displays no information.

    Edit: I think it's also worth noting that if you do decide to use the the header() method, you need to make sure your sleep() duration isn't too long. I think most browsers generate a connection timed out after not receiving any data from the server for 1 minute.

    0 讨论(0)
  • 2020-12-28 19:49

    If you want to wait and then go back to the previous page here's how

    $referrer = $_SERVER['HTTP_REFERER']; 
    
    header ("Refresh: 2;URL='$referrer'"); 
    
    0 讨论(0)
  • 2020-12-28 19:52

    This one should works:

    <?php
    header('Refresh: 5; URL=http://yoursite.com/page.php');
    //other code
    ?>
    

    and will allow your user to see whatever kind of output you want (You'll be redirected in X Seconds, click yere if dont, etc..)

    0 讨论(0)
  • 2020-12-28 19:56

    Try:

    <?php
    $url=base_url().'page_you_want_to_go_to'
    header('Refresh: X; URL=$url');
    ?>
    

    This will give you additional flexibility when exchanging between localhost and remote server.

    0 讨论(0)
  • 2020-12-28 19:56

    put this in the header.

     <meta http-equiv="refresh" content="0.01;makensucces.html" />  
    

    on the place 0.01 you must put the seconds, i have used an decimal number.

    and on the place of makensucces.html you need to put the name off the file you desire.

    0 讨论(0)
提交回复
热议问题