Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait-time before redirect in PHP

This is my code on page1:

session_start();
if(isset($_SESSION[$login])){
    header("Refresh: 5; location:page2.php");
    echo "Welcome back!";
}

I thought this was the way to have a redirect on page2 AFTER 5 seconds of pause, in which the user can see the message "Welcome Back". Am I wrong?

The result of my code is a correct identification of the login, with the consequent showing of echo "Welcome Back", but the redirect isn't happening. I remain in page1 forever.

Where is the error?

ps: I made a search of similar threads, but I hadn't be able to solve the problem, so I'm posting here guys, thank you!

like image 240
noobsharp Avatar asked Jul 25 '26 02:07

noobsharp


1 Answers

I believe you need to use url= rather than location:

header("Refresh: 5; url=page2.php");

Unfortunately, this is a non-standard way of doing redirection (and not a great one at that), so I have been unable to find any documentation for it.

like image 130
lonesomeday Avatar answered Jul 28 '26 02:07

lonesomeday



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!