简体   繁体   中英

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. Because the google.com is giving the url to my page where there is no more data like index.php?id=10. So, I need to revert the url to index.php on first time only. 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. 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");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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