dcsimg
www.webdeveloper.com
Results 1 to 11 of 11

Thread: Exam timer and refresh

  1. #1
    Join Date
    Apr 2017
    Posts
    4

    Exam timer and refresh

    I have already built an online exam portal, which allows student to take exam online using web browser.

    Now in that I also have developed timer function wherein user has to complete the exam within stipulated time frame. What I am getting trouble is that when I refresh the page the timer again start from fresh for example 40 minutes, What I want is when user refresh the page it should not reinstate the timer or same case when they click on next question button.

    The context here is Lotus Domino but I want to achieve the things using javascript, is there anyway we can store the timer value before the page was refreshed or page submitted and when post refreshing / next question it should start from past value..

    If any solution which can be used without storing the values in Javascript Coockies or storing it in indexedDB of latest browser would be highly appreciated.

    Also note that this is online exam using web browser so any other solution like disabling refresh, disabling other menus of browser would be highly accepted.

    Thanks
    hd

  2. #2
    Join Date
    Dec 2012
    Posts
    1,555
    is there anyway we can store the timer value before the page was refreshed or page submitted and when post refreshing / next question it should start from past value..
    Yes, that's fairly easy: Make yourself familiar with localstorage.

  3. #3
    Join Date
    Apr 2017
    Posts
    4
    thanks for your reply but I am looking solution which would help me without local storage, please note that user can always change the local storage and can do alteration with it.

  4. #4
    Join Date
    Dec 2012
    Posts
    1,555
    That's true but this applies to any kind of client side / Javascript solution. To avoid manipulations you need a server side solution: Store the time when the exam started and check it when the result is submitted, both on the server. However you will need kind of user management for doing so.

  5. #5
    Join Date
    Apr 2017
    Posts
    4
    Yes, While submitting I will make sure the values are being stored in Back end, but my question is that when user refreshes the page.. What is best way either I can avoid it , or typical exam environment what would be best solution for this.

  6. #6
    Join Date
    Dec 2012
    Posts
    1,555
    When you have stored the starting time on the server it's easy to subtract current time - starting time and transmit it to the client when the page is refreshed. Then you can set the value of the timer to it's appropriate value.

  7. #7
    Join Date
    Apr 2017
    Posts
    4
    Quote Originally Posted by Sempervivum View Post
    When you have stored the starting time on the server it's easy to subtract current time - starting time and transmit it to the client when the page is refreshed. Then you can set the value of the timer to it's appropriate value.
    For example each survey has 40 minutes which value is stored in backend.

    Can you please help me understanding how excate this would transmitted to the client side of browser when page gets refreshed and current time value remaining is 23:33 (mm:as) ?

  8. #8
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,429
    IMHO you set the start time on the server that sets a timer on the current page of the test that indicates the time the survey / test will end by.

    Each time a question is answered, the time reference for that question is stored and passed back to the server to see if it is within time, if it is then the next question is retrieved and displayed.

    If you use a future time reference for when the survey / test finishes, you wouldn't need to store anything in localStorage.

    The only issue that you will have with sync to server is the time zone differences, so you would need to allow for any DLS and offsets when using future times.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  9. #9
    Join Date
    Dec 2012
    Posts
    1,555
    how excate this would transmitted to the client side of browser
    Does this answert your question?:
    <?php
    // $startingtime: Time when exam was started in seconds
    // I assume that this value is available
    // $currenttime: Current time in seconds, can be easily determined
    $timervalue = $currenttime - $startingtime;
    ?>
    <script>
    var timervalue = <?php echo $timervalue; ?>;
    // Current value for timer in seconds now available in this variable
    </script>

  10. #10
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,429
    more simpler to pass a reference to the script and get it to make a date object on the client from the one on the server.
    PHP Code:
    <?php
        session_start
    ();
        
    date_default_timezone_set("UTC");
        if( !isset( 
    $_SESSION['start_time'] ) ) $_SESSION['start_time'] = date("r");
    ?>
    <script>
        var serverTime = new Date("<?php echo  $_SESSION['start_time']; ?>"); // take time form time object in conventional way
        var nowTime = serverTime.toUTCString();
    </script>
    Putting the same type of header in each page will ensure that the start time was selected. HOWEVER.. this time reference will be whatever the network time for the servers are and not the local time of the client, so tell PHP to use UTC time reference for timezone.

    It would be better to produce a time reference when to finish by.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  11. #11
    Join Date
    Apr 2017
    Posts
    4
    Similar problem here - with solution

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center