Jump to content

[SOLVED] PHP Sleep() help


shakeit

Recommended Posts

Hello Everyone.

 

I've been sitting for quite a while now, reading the sleep() manual and tried to turn the code upside down and inside out but nothing helps... I want the current page to wait a few seconds before it is directed to another ( after a successfull registration ). So i thought the best way to do that is to use sleep().

 

However, this does work to a certain point ... the current page waits for 5 seconds, but the text I want to show the user in the meantime doesn't show? Why? Without the sleep() and the header() it shows without any problem. Can anyone please help?

 

if( $add_user == 1 )

{

          // This method returns true if the registration is successfull

$check = $min->register($name, $adress, $age, $email, $phone, $country,$city, $newsletter, $uname, $password, $password2 );

 

          if( $check )

          {

                  $name = ""; $adress = ""; $age = ""; $email = ""; $phone = ""; $country = ""; $city = ""; $newsletter = ""; $uname = ""; $password = ""; $password2 = "";

 

                  echo "Successfull registration";      // <-------- THIS STRING DOESN'T SHOW

      sleep(5);

      header("Location: $loginHeader");

          }

}

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/77515-solved-php-sleep-help/
Share on other sites

sleep() will sleep in the execution of the script thus resulting in the script "hanging" (at least it will look like that to the user). You should simply use a Refresh header instead of a Location header if you wish to delay the redirection.

 

Refresh: 5; url=http://example.com

Link to comment
https://forums.phpfreaks.com/topic/77515-solved-php-sleep-help/#findComment-392368
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.