Redirect with Timer in PHP?

前端 未结 11 2086
刺人心
刺人心 2020-12-28 11:49

How can I make a redirect with PHP after say 10 seconds...

I have read alot about it, seems like it would be better with javascript. But PHP would save me alot of co

11条回答
  •  太阳男子
    2020-12-28 12:23

    I managed to do it with a simple function on PHP

    function RedirectToURL($url, $waitmsg = 0.4)
    {
        header("Refresh:$waitmsg; URL= $url");
        exit;
    }
    

    and you call from your PHP for waiting 2 seconds before redirect. Note that $waitmsg = 0.4 is used for defining the default value.

    RedirectToURL("http://website.php", 2);
    

    If you want to redirect after a form submit, you can try

    if(isset($_POST['submitted']))
    {
           echo '


    Sucess. Thanks for contribution.
    '; RedirectToURL("http://thewebsiteilookforaftersubmit", 2); // I want to wait 2 seconds and not 0.4 as defined by default }

提交回复
热议问题