[英]How to reload the Page by header at first time only
我需要在第一次页面加载时立即重新加载或刷新页面(index.php)。 因为google.com会将网址提供给我的页面,所以没有其他数据,例如index.php?id = 10。 因此,我只需要在第一次将URL还原为index.php。 我需要以简单的方式解决。 请任何帮助?
我建议您使用$_SESSION
全局数组,因为它允许您轻松地将信息从一页传递到另一页(或同一页,如本例所示)。 但是,请确保在使用它的每个页面上初始化会话。
代码应该是这样的:
session_start(); //Important! Without this, $_SESSION doesn't work
//reload_index is a variable I'm using in the array, nothing restricted; you can use whichever name you like
if (!isset($_SESSION['reload_index']) || ($_SESSION['reload_index'] == 'yes'))
{
$_SESSION['reload_index'] = 'no';
header("Location: index.php"); //Or whatever page you want to go; you can add parameters as well, like index.php?id=10
}
//...Rest of the page
我希望这可以帮助您解决问题。 最好的祝福。
检查会话中是否设置了标志。 如果没有,请进行设置并重新加载页面。 简单的伪代码示例:
session_start();
if (!isset($_SESSION['redirect_flag'])) {
$_SESSION['redirect_flag'] = true;
header("Refresh:0; url=index.php");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.