10-24-2008, 10:18 AM
|
#7 (permalink)
|
|
The Wanderer
Join Date: Jan 2008
Posts: 24
Thanks: 13
|
The PHP-function "sleep()" should do it. Here's just a (somewhat nonsensical) sample script that delays a defined action while displaying a countdown, without the use of javascript. You should get the idea ...
Code:
function delayAction($action, $delay=5, $frequency=1, $confirm=FALSE)
{
ob_implicit_flush(TRUE);
for($i = 0; $i < $delay; $i++)
{
// Important! Style boxes and make sure the z-index rises with each call. Also set a background-color so that underlying layer is covered.
$countdown_pat = "<div style=\"position:absolute;z-index:".$i.";background:#FFF;\">%s</div>";
$confirm_pat = "<div style=\"position:absolute;z-index:".$i.";background:#FFF;\"><h2>Really? <a href=\"%s\">Confirm</a> / <a href=\"%s\">Undo</a></h2></div>";
$redirect_pat = "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=%s\">";
// "Pulsate" until delay is reached. Then perform action.
if($i < $delay-1)
{
// Display countdown
printf($countdown_pat, date('h:i:s'));
// "Pulsate"
sleep($frequency);
}else{
if($confirm == FALSE)
{
// Redirect
printf($redirect_pat, $action);
}else{
// Display confirmation-link
printf($confirm_pat, $action, $_SERVER['PHP_SELF']);
}
}
}
}
// Test
$frequency = 1; // Set "pulse" in seconds
$delay = 5; // Set delay + 1 in seconds
$action = "http://boldeagle.org"; // Set action. (Here I'm setting the location for a meta-refresh/link)
// Execute with custom settings (with confirmation-link)
delayAction($action, $delay, $frequency, 1);
// Execute with default settings (without confirmation-link)
//delayAction($action);
|
|
|
|