Page 1 of 1

PHP live timer ---help me

Posted: Fri Nov 14, 2008 5:14 am
by nummish_girish
:banghead:

im writing a code for online test, for which i need a timer , which counts down say for 60min....within which, the paper time must expire.
i have taken the timestamp from the server and displayed in browser.



This is the file called countdown.php

Code: Select all

 
<?php
 
 
 
//$target_date = mktime(hour, minute, second, month, day, year)
 
$month = 11;
$dat = date('H:i:s');
 
 
$event_length = 30;  //here i m adding the test time taken by the student to time obtained by the server.
$timestamp = strtotime("$dat");
$etime = strtotime("+$event_length minutes", $timestamp);
$next_time = date('H:i:s', $etime);
list($hour, $minute, $second) = explode(':' , $next_time);
//echo $minute;
echo"<br> </br>";
 
 
$input=$_GET['timestamp'];
echo"<br> </br>";
 
echo $input;
 
 
$target_date = mktime($hour, $input, $seconds, $month, 14, 2008);
 
$today_date = time();
 
$secs_left = $target_date - $today_date;
 
 
 
 
if ($secs_left > 0) //not yet reach target date
 
{
 
 
 
//1 day is 86400 seconds (60 * 60 * 24)
 
$days_left = floor($secs_left / 86400);
 
 
//1 hour is 3600 seconds (60 * 60)
 
$hrs_left = floor(($secs_left - $days_left * 86400) / 3600);
 
 
//1 minute is 60 seconds 
 
$mins_left = floor(($secs_left - ($days_left * 86400) - ($hrs_left * 3600)) / 60);
 
 
 
$secs_left = $secs_left - ($days_left * 86400) - ($hrs_left * 3600) - ($mins_left * 60);
 
 
 
// "<strong>".$days_left."</strong> day : ".
 
 
//"<strong>".$hrs_left."</strong> hr : ".
 
echo"<strong>".$mins_left."</strong> min : ".
 
"<strong>".$secs_left."</strong> sec";
 
 
//echo"<input type='text' id='stop' value=$secs_left></input> ";
 
}
 
 
 
 
else              //target date reached!
 
{
 
// here i should expire the TEST taken or Test time out
 
}
 
 
 
?>
 
 
this is the page called countdown.html

Code: Select all

 
<html>
<title> Countdown Clock</title>
 
</head>
 
<body>
<script type="text/javascript" src="prototype.js"></script>
 
<script type="text/javascript">
 
new Ajax.PeriodicalUpdater ( "countdown", "countdown_1.php", { method: "get", frequency: 1 } );
 
</script>
 
<div id="countdown"></div>
 
</body>
 
</html>
 
 
what i wanted to is when the timer countdown comes to zero, i must execute the test timeout condition.


please any one help me.....
thank u in advance...

Re: PHP live timer ---help me

Posted: Fri Nov 14, 2008 8:53 am
by aaronhall
As long as your depending on javascript, you may as well use settimeout("window.location='[timeout page]'", 1000*60*60). I'd also track the test start time in a cookie session and compare against that.

Re: PHP live timer ---help me

Posted: Sun Nov 16, 2008 10:45 pm
by nummish_girish
thank u