is there a Wait x second function?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

is there a Wait x second function?

Post by Mythic Fr0st »

Im wondering if there is a wait(5.00) second function, so I can say, wait 5 seconds before redirecting
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post 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");
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post 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>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

that's ok, not everah... but I keep thinking the same thing because of their similar avatars
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

ok

Post by Mythic Fr0st »

Thanks guys, i'll try it
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post 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
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
Post Reply