yaseen ahmed
yaseen ahmed

Reputation: 21

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?

Upvotes: 0

Views: 708

Answers (2)

kano
kano

Reputation: 5920

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");
}

Upvotes: 0

Ignacio Téllez
Ignacio Téllez

Reputation: 451

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.

Upvotes: 1

Related Questions