Redirect with Timer in PHP?

前端 未结 11 2085
刺人心
刺人心 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:19

    After the Web Page loads, PHP no longer runs. This means that you can't do anything with PHP after the page loads unless you use something like AJAX(Javascript calling a PHP page) to transfer data to the page. This presents you with a few methods to achieve your desired 10 second wait on redirect.

    First, you could tell your script to sleep() for 10 seconds. This however, as Johnathan mentioned, means that you would look like your page was really slow, only to have the user redirected.

    sleep(10);
    

    You could also simply drop in a META tag that tells the page to redirect itself after 10 seconds. This is the preferred method, as it doesn't involved almost any other coding, as you simply drop in the META tag, and you don't have to deal with javascript at all.

    
    

    Then, you could also have Javascript issue a location.href="bleh"; command after waiting for 10 seconds.

提交回复
热议问题