2 Replies - 868 Views - Last Post: 26 March 2013 - 08:24 AM Rate Topic: -----

#1 neo112  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 24
  • Joined: 23-November 12

how to make a redirect timer?

Posted 26 March 2013 - 07:45 AM

I'm creating a webpage that has a login and register pages, login.php and register.php respectively.

I've run into a little problem. If an already logged in user somehow ends up on register.php, I want to display them a message for 5 seconds and then redirect them to the mainpage.php.

To do this, I wrote a simple check on register.php that checks if $_SESSION['CurrentUser'] is set ->redirect to mainpage.php.
if(isset($_SESSION['CurrentUser'])) {
	$now = time();
	$then = $now + 5;
	
	echo "Redirecting to mainpage";
	header("Location: mainpage.php");
}



Now the problem is that the redirect happens instantly, how can I make it display a message ,wait for 5 seconds, and then redirect?

Is This A Good Question/Topic? 0
  • +

Replies To: how to make a redirect timer?

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3515
  • View blog
  • Posts: 10,143
  • Joined: 08-June 10

Re: how to make a redirect timer?

Posted 26 March 2013 - 07:56 AM

you can use the refresh meta element, e.g. <meta http-equiv="refresh" content="5;URL='http://example.com/'">.

AFAIK, there is no way to do that in PHP alone (as PHP on the server is not concerned with what happens on the client).
Was This Post Helpful? 1
  • +
  • -

#3 neo112  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 24
  • Joined: 23-November 12

Re: how to make a redirect timer?

Posted 26 March 2013 - 08:24 AM

that worked, ty!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1