Page 1 of 1

is there a Wait x second function?

Posted: Mon Dec 04, 2006 4:28 pm
by Mythic Fr0st
Im wondering if there is a wait(5.00) second function, so I can say, wait 5 seconds before redirecting

Posted: Mon Dec 04, 2006 4:30 pm
by ok
You mean redirecting with PHP, so yes:

Code: Select all

<?php
// Do what you need to do...
sleep(5);
header("Location: next.php");

Posted: Mon Dec 04, 2006 4:34 pm
by Luke
If you are going to use this to display a message to the user before redirecting like this...

Code: Select all

<?php
$message = 'We are redirecting you...';
echo  $message;
sleep(5);
header('Location: http://www.somewhere.com');
?>
You're going to be in for a nasty surprise...
Headers already sent on line XX

Posted: Mon Dec 04, 2006 4:40 pm
by ok
If you want to add a message you need to use HTML or AJAX.
HTML:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html dir="ltr" xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>Please Wait...</title>
  <meta http-equiv="Refresh" content="5; url=http://example.com/index.php" />
 </head>
 <body>
 Wait 5secs or <a href="http://example.com/index.php" title="">click here</a>.
 </body>
</html>

Posted: Mon Dec 04, 2006 5:55 pm
by s.dot
I'd go everah's route. sleep()ing before a header() call doesn't make much sense to me since you can't send a message. Do it in the meta tag.

Posted: Mon Dec 04, 2006 6:01 pm
by Luke
that's ok, not everah... but I keep thinking the same thing because of their similar avatars

ok

Posted: Mon Dec 04, 2006 6:26 pm
by Mythic Fr0st
Thanks guys, i'll try it

Posted: Mon Dec 04, 2006 6:47 pm
by RobertGonzalez
The Ninja Space Goat wrote:that's ok, not everah... but I keep thinking the same thing because of their similar avatars
<Off topic>
<--- My penguin is sooo much cooler... just look at him. All cute and fat and rotund and plump. Mmm, makes me want chicken.
</Off topic>

I'd use ok suggestion... HTML meta redirection.

Posted: Tue Dec 05, 2006 4:29 am
by onion2k
ok wrote:If you want to add a message you need to use HTML or AJAX.
What on Earth does this sort of thing have to do with AJAX?

Posted: Tue Dec 05, 2006 9:18 am
by feyd
onion2k wrote:What on Earth does this sort of thing have to do with AJAX?
Because Ajax is the solution for everything these days. It's the buzzword, man!

Image

Posted: Tue Dec 05, 2006 11:36 am
by ok
Everah wrote:
The Ninja Space Goat wrote:that's ok, not everah... but I keep thinking the same thing because of their similar avatars
<Off topic>
<--- My penguin is sooo much cooler... just look at him. All cute and fat and rotund and plump. Mmm, makes me want chicken.
</Off topic>
LOL :D

Posted: Tue Dec 05, 2006 12:03 pm
by AKA Panama Jack
Yeah, use the META tags instead of using the SLEEP function. Many shared hosting services have the SLEEP function disabled in PHP.