sleep() touble

Thread Solved

Join Date: Oct 2008
Posts: 42
Reputation: JimD C++ Newb is an unknown quantity at this point 
Solved Threads: 0
JimD C++ Newb JimD C++ Newb is offline Offline
Light Poster

sleep() touble

 
0
  #1
Apr 6th, 2009
Good morning!

What I am trying to do is: display some text, wait 3 seconds (so the person can read it) and redirect that person to a different web page.

I can get it to either:

1 - Display the text or
2 - Sleep(3) and redirect them to the specific web page.

But I cannot get it to do both.

Can somebody please point me in the right direction?

Thank you in advance

  1. <?php
  2. echo "Your username and password do not match our records";
  3. sleep(3);
  4. header("Location: movie_registration.php");
  5. ?>
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 232
Reputation: samarudge is an unknown quantity at this point 
Solved Threads: 19
samarudge samarudge is offline Offline
Posting Whiz in Training

Re: sleep() touble

 
1
  #2
Apr 6th, 2009
There are many problems with that.
1 - Unless you spacificaly tell it, PHP will wait till the end of the script before sending ANY information to the browser so that script would not be sent till after 3 seconds.
2 - If it was shown then header() would not work as headers need to be sent before any data.
3 - Most browsers (IE, Netscape/firefox etc) only update the display every 100bites or so

Try this
  1. <?php
  2. header("Refresh: 3;URL=movie_registration.php");
  3. echo "Your username and password do not match our records";
  4. ?>
This will display the page but tell the browser to refresh after 3 seconds to the new page
Regards,
Sam Rudge
My Blog, Life and everything that matters to me - SamRudge.co.uk

2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 42
Reputation: JimD C++ Newb is an unknown quantity at this point 
Solved Threads: 0
JimD C++ Newb JimD C++ Newb is offline Offline
Light Poster

Re: sleep() touble

 
0
  #3
Apr 6th, 2009
Oh that worked perfectly!

Thank you so much for the explanation! That makes sense to me now.

- Jim
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC