我需要在第一次页面加载时立即重新加载或刷新页面(index.php)。因为 google.com 提供的是我的页面的 url,其中没有更多数据,例如 index.php?id=10。因此,我只需要在第一次时将 url 恢复为 index.php。我需要简单的解决方案。请帮忙吗?
最佳答案
我建议您使用 $_SESSION
全局数组,因为它允许您轻松地将信息从一个页面传递到另一个页面(或同一页面,如本例)。不过,请确保在使用它的每个页面上初始化 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
希望这能帮助您解决问题。谨致问候。
关于javascript - 如何仅在第一次时按标题重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35370350/