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
}
?>
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>
please any one help me.....
thank u in advance...