PHP Question : The echo message didnt show up [duplicate]

I have a simple question but yet i don't know. I would like to display message first before redirect to other page, but my code just directly redirect the page without display the message, or the display time is too short am not sure.. my code as below.. pls advise. thank much.

echo "Please Log In First";
header("location: login6.php");

Solution 1:

You can't do it that way. PHP header must sent out before any content, so the correct order is:

header("location: login6.php");
echo "Please Log In First";

But these codes will redirect instantly and wouldn't let you see the content. So I would do the redirection by JavaScript:

echo "Please Log In First";
echo "<script>setTimeout(\"location.href = 'http://www.example.com';\",1500);</script>";

Solution 2:

You can use header refresh. It will wait for specified time before redirecting. You can display your message then.

header( "refresh:5; url=login.php" ); //wait for 5 seconds before redirecting