加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 标题位置延迟

发布时间:2020-12-13 13:15:55 所属栏目:PHP教程 来源:网络整理
导读:我有以下 PHP代码,我想添加延迟: ?php echo "Message has been sent."; header("Location: page2.php",true,303); exit;? 上面的代码发生得太快,所以我看不到消息: 我试过了: ?php sleep(5); echo "Message has been sent."; header("Location: page2.php
我有以下 PHP代码,我想添加延迟:
<?php
    echo "Message has been sent.";
    header("Location: page2.php",true,303);
    exit;
?>

上面的代码发生得太快,所以我看不到消息:

我试过了:

<?php
    sleep(5);
    echo "Message has been sent.";
    header("Location: page2.php",303);
    exit;
?>

这也没有显示消息,但它会睡5秒钟,这只是浪费时间.

在重定向之前,如何让它显示5秒钟的消息?

您无法通过HTTP位置重定向执行此操作,因为只要浏览器获得标头,就会发生此重定向.而是在标头中使用刷新重定向:
header( "Refresh:5; url=http://www.example.com/page2.php",303);

这应该适用于现代浏览器,但它不是标准化的,所以要获得相同的功能,请使用元刷新重定向(意味着您还必须输出完整的HTML):

<meta http-equiv="refresh" content="5;url=http://www.example.com/page2.php">

从the Wikipedia page开始:

Used in redirection,or when a new resource has been created. This refresh redirects after X seconds. This is a proprietary,non-standard header extension introduced by Netscape and supported by most web browsers.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读