在重定向到其他页面之前显示消息 [英] Display message before redirect to other page

查看:90
本文介绍了在重定向到其他页面之前显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题,但我不知道.我想先显示消息,然后再重定向到其他页面,但是我的代码只是直接重定向页面而不显示消息,或者显示时间太短不确定..我的代码如下.非常感谢.

I have a simple question but yet i don't know. I would like to display message first before redirect to other page, but my code just directly redirect the page without display the message, or the display time is too short am not sure.. my code as below.. pls advise. thank much.

echo "Please Log In First";
header("location: login6.php");

推荐答案

您不能那样做. PHP标头必须在任何内容之前发送出去,因此正确的顺序是:

You can't do it that way. PHP header must sent out before any content, so the correct order is:

header("location: login6.php");
echo "Please Log In First";

但是这些代码将立即重定向,并且不会让您看到内容. 因此,我将通过JavaScript进行重定向:

But these codes will redirect instantly and wouldn't let you see the content. So I would do the redirection by JavaScript:

echo "Please Log In First";
echo "<script>setTimeout(\"location.href = 'http://www.example.com';\",1500);</script>";

这篇关于在重定向到其他页面之前显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆