hi,
Am a newbie in php,i want to set a countdown timer for online quiz in php.
when an student login,there wil be a home page and in home page there are two php pages like quiz.php and result.php, So When the studuent selects quiz.php,he will be redirected to quiz.php and he can answer the question given,when student select quiz.php and page is redirected to quiz.php,the timer should start and there should be a countdown of time also and the timer should be set to a certain time period,so when timer reaches 0,the quiz.php should appear blank and should be redirected to home page.where the student can see the result.
can someone please help out with the php code for this and how to implement it.

Welcome to DaniWeb. This looks very much like a homework assignment, which our members will be happy to help you with but not actually complete for you. So to move forward, you need to let us know exactly where you are having difficulties with your code (and you should share your code with us so we can see where the problem is) and what you don't understand...

hey thanks for replying,i have executed the below code:
Everything works well,and I've done where all questions get selected randomly from database one at a time,and i have kept each questions in different php pages,where the timer begins when the user login and start answering the first question,then when the user selects next question,the timer agains start from the beginning time,but i need the timer count to continuously displayed for all questions while user is taking the quiz.Can u please help out with this.

<?php
    session_start();
    if( empty( $_SESSION['quiz'] ) )$_SESSION['quiz']=date('Y-m-d H:i:s');
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language ="javascript" >
    <?php
              $start=$_SESSION['quiz'];
              $end=date('Y-m-d H:i:s', strtotime( $_SESSION['quiz'] . ' +20 minutes' ) );
                echo "
                    var date_quiz_start='$start';
                    var date_quiz_end='$end';
                    var time_quiz_end=new Date('$end').getTime();";
      ?>
        var tim;
        var hour= 00;
        var min = 01;
        var sec = 60;
        var f = new Date();
        function f1() {
            f2();
            document.getElementById("starttime").innerHTML = "Your started your Exam at " + f.getHours() + ":" + f.getMinutes();

        }
        function f2() {
            if (parseInt(sec) > 0) {
                sec = parseInt(sec) - 1;
                document.getElementById("showtime").innerHTML = "Your Left Time  is :"+hour+" hours:"+min+" Minutes :" + sec+" Seconds";
                tim = setTimeout("f2()", 1000);
            }
            else {
                if (parseInt(sec) == 0) {
                    min = parseInt(min) - 1;
                    if (parseInt(min) == 0) {
                        clearTimeout(tim);
                        location.href ="index.php";
                    }
                    else {
                        sec = 60;
                        document.getElementById("showtime").innerHTML = "Your Left Time  is :" + min + " Minutes ," + sec + " Seconds";
                        tim = setTimeout("f2()", 1000);
                    }
                }

            }
        }
    </script>
</head>
<body onload="f1()" >
    <form id="form1" runat="server">
    <div>
      <table width="100%" align="center">
        <tr>
          <td colspan="2">
          </td>
        </tr>
        <tr>
          <td>
            <div id="starttime"></div><br />
            <div id="endtime"></div><br />
            <div id="showtime"></div>
          </td>
        </tr>
        <tr>
          <td>

              <br />

          </td>

        </tr>
      </table>
      <br />

    </div>
    </form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.