dopr25398 2018-12-03 02:22
浏览 59

如何在php中启用javascript启用的倒计时器?

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);
    ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型