views:

33

answers:

2

Hi there! I would like to make my PHP script freeze at a screen for at least 5 seconds before loading into the next script. I have tried "Sleep()" however that is not the function I am looking for as it only pause the script that is "going" to be loaded.

Here are my codes:

echo "Welcome ",$_SESSION['username']."<br>";
    echo "Click here to Logout :    ".'<br><a href="logout.php">Logout</a>';

    sleep(10);

    header("Location: http://192.168.11.32/phploginserver/test.php");

    echo '<script type="text/javascript">window.location="test.php"</script>';    
}

I would like the echo'to another page' to be delayed for at least 5 seconds before loaded so that my users can view their user name before being automatically redirected to the next page.

Please share your views. Thanks!

A: 

You cannot freeze PHP script at a screen.
Just because there are no PHP scripts at screen. But merely HTML, rendered by browser.

Such a freezing considered bad practice and don't used nowadays.
Either show a message, if it's really important, or get user to the destination immediately (preferred).
You can use some AJAX-powered tips, as stackoverflow does.

so that my users can view their user name

Don't they know it already?
Can't they see it on the next page?
What if a user got disturbed and do not notice that message?

Col. Shrapnel
I am just doing some pentesting here. You can relax there a bit sir.
JavaNoob
@Java whats the point in testing useless and obsolete technology? It's not time to relax, as you don't know the very basics. Learn hard and by time you can achieve some respect.
Col. Shrapnel
Well got got to test in order to learn same goes for the famous quote "hack to learn instead of learn to hack" anyway I guess your answer was right. Seems that no one else knows how to do it properly.
JavaNoob
@Java not "how" but "what for" lol :) For "how" it's only your fault, the way you asked this question. These poor SO yokels took it literally, as usual. Actually it's very easy to implement and you can learn it in 5 seconds, just by going to any site that still does this ancient thing, and studying page source. If you really prefer hack to learn, hehe :)
Col. Shrapnel
A: 
$time = new DateTime();
$newtime = $time->Modify("+5 seconds");



while($newtime > (new DateTime()))
    {
    // Do nothing
    }
oddi
You can just use pause(5); for a shorter version of your codes.
JavaNoob