943,975 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1301
  • PHP RSS
Apr 6th, 2009
0

sleep() touble

Expand Post »
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

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. echo "Your username and password do not match our records";
  3. sleep(3);
  4. header("Location: movie_registration.php");
  5. ?>
Reputation Points: 10
Solved Threads: 0
Light Poster
JimD C++ Newb is offline Offline
46 posts
since Oct 2008
Apr 6th, 2009
1

Re: sleep() touble

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
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 26
Solved Threads: 31
Posting Whiz
samarudge is offline Offline
354 posts
since May 2008
Apr 6th, 2009
0

Re: sleep() touble

Oh that worked perfectly!

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

- Jim
Reputation Points: 10
Solved Threads: 0
Light Poster
JimD C++ Newb is offline Offline
46 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: vBulletin to ASP.NET
Next Thread in PHP Forum Timeline: PHP FTP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC