I have written php code for an examination portal using javascript enabled countdown timer. When i run my code in localhost its fine. But in server, the clock gets stopped after some time, what might be the problem? Below is the part of related codes. Thank you!!! In portal.php
<?php
$_SESSION['exam_length'] = $all_questions[0]->exam_length;
$_SESSION['start_time'] = date('Y-m-d H:i:s');
$end_time = date('Y-m-d H:i:s',strtotime('+'.$_SESSION['exam_length'].'minutes',strtotime($_SESSION['start_time'])));
$_SESSION['end_time'] = $end_time;
?>
<div class="col-md-3 col-lg-3 col-sm-3" id="response" style="font-size: 25px; position: fixed; right: -7px;"></div>
<script type="text/javascript">
setInterval(function()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","response.php",false);
xmlhttp.send(null);
document.getElementById('response').innerHTML=xmlhttp.responseText;
},1000);
exam_length = '<?php echo (($all_questions[0]->exam_length)*60000); ?>';
var auto_refresh = setInterval(function() { submitform(); },exam_length);
</script>
In response.php:
<?php
session_start();
if(($_SESSION['is_logged_in'])=="")
{
@header("location:../");
exit;
}
$from_time1 = date('Y-m-d H:i:s');
$to_time1 = $_SESSION['end_time'];
$timefirst = strtotime($from_time1);
$timesecond = strtotime($to_time1);
$difference_second = $timesecond - $timefirst;
echo gmdate("H:i:s",$difference_second);
?>