简体   繁体   English

仅在第一次时如何重新按标题页

[英]How to reload the Page by header at first time only

I need to reload or refresh the Page (index.php) at once on first time page loading. 我需要在第一次页面加载时立即重新加载或刷新页面(index.php)。 Because the google.com is giving the url to my page where there is no more data like index.php?id=10. 因为google.com会将网址提供给我的页面,所以没有其他数据,例如index.php?id = 10。 So, I need to revert the url to index.php on first time only. 因此,我只需要在第一次将URL还原为index.php。 I need solution in simple way. 我需要以简单的方式解决。 please any help? 请任何帮助?

I'd recomend you use $_SESSION global array, for it allows you to pass information from one page to another (or the same one, like in this case) easily. 我建议您使用$_SESSION全局数组,因为它允许您轻松地将信息从一页传递到另一页(或同一页,如本例所示)。 Be sure you initialize sessions on each page you use it, though. 但是,请确保在使用它的每个页面上初始化会话。

The code should be something like this: 代码应该是这样的:

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

I hope this helps you resolve your problem. 我希望这可以帮助您解决问题。 Best regards. 最好的祝福。

Check if a flag is set in session. 检查会话中是否设置了标志。 If not, set it and reload your page. 如果没有,请进行设置并重新加载页面。 Simple pseudo-code example: 简单的伪代码示例:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM