在PHP中使用Timer重定向? [英] Redirect with Timer in PHP?
问题描述
说10秒钟后如何使用PHP进行重定向...
How can I make a redirect with PHP after say 10 seconds...
我已经阅读了大量有关它的内容,似乎使用javascript会更好.但是PHP可以节省很多代码.
I have read alot about it, seems like it would be better with javascript. But PHP would save me alot of coding.
那么如何在PHP中使用计时器进行重定向?
So how can I make a redirect with timer in PHP ?
谢谢
推荐答案
您可以使您的PHP脚本休眠10秒钟,
You can cause your PHP script to sleep for 10 seconds,
sleep(10);
,但这对于最终用户将显示为无响应服务器.最好的选择是使用元刷新,
but this will appear to the end-user as a non-responsive server. The best option is to use either a meta refresh,
<meta http-equiv="refresh" content="10;url=http://google.com">
或javascript.
or javascript.
setTimeout(function(){
window.location = "http://google.com";
}, 10000);
在丹尼尔的评论中找到:
Found in the comments from Daniel:
header('Refresh: 10; URL=http://yoursite.com/page.php');
对于这种情况将是理想的,因为它不需要Javascript或HTML.
would be ideal for this situation, as it requires no Javascript or HTML.
这篇关于在PHP中使用Timer重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!