Results 1 to 7 of 7

Thread: How to count time from when user load a page/form until they submit it?

  1. #1
    Join Date
    Aug 2006
    Posts
    58
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Arrow How to count time from when user load a page/form until they submit it?

    Hi

    I'm trying to create a quiz using php & html forms, I am planning to count the time used by the user to complete the form, and then posting it in the database and producing a highscore list sorted by the actual quiz score and completion time.

    The problem is, I don't know how to count the time from when user loads the page of the quiz and submit the form..

    Could anyone give me some pointers?

    Thanks in advance, I would very much appreciate your help

  2. #2
    Join Date
    Mar 2011
    Posts
    2,171
    Thanks
    61
    Thanked 121 Times in 117 Posts
    Blog Entries
    4

    Default

    Php can only interact with the webpage before it loads so it would be hard to make a timer that runs off php. Using javascript, this would be simple enough.
    Google javascript countdown.

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,435
    Thanks
    105
    Thanked 118 Times in 116 Posts

    Default

    I think you are misunderstanding his question keyboard1333.

    Just create a database with a unique value for the user like a cookie and then store the cookie in the database under the field cookie and next to it store the login datetime. When the quiz is completed the user will click the submit button. At this point the datetime value is stored in the database and the difference between the two database values is retrieved and displayed. If you want you could then store the time to complete the quiz in the database as well in case the person wants to try again and beat their current score.
    To choose the lesser of two evils is still to choose evil. My personal site

  4. #4
    Join Date
    Mar 2011
    Posts
    2,171
    Thanks
    61
    Thanked 121 Times in 117 Posts
    Blog Entries
    4

    Default

    Quote Originally Posted by k12onos View Post
    Hi
    The problem is, I don't know how to count the time from when user loads the page of the quiz and submit the form..
    I assumed he meant a visible countdown on the page so the user can see how long the're taking. Wouldn't that be more user friendly as it would make them try harder to beat their score? And you can still calculate the overall time.

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,435
    Thanks
    105
    Thanked 118 Times in 116 Posts

    Default

    It is possible that is what he meant, but he mentioned php, form, and database as well as displaying the results in the form of a list. This led me to think he was not talking about a javascript timer. Either method should work.

    The javascript method may be more user friendly. I personally prefer it without, but that's just me.
    To choose the lesser of two evils is still to choose evil. My personal site

  6. #6
    Join Date
    Mar 2011
    Posts
    2,171
    Thanks
    61
    Thanked 121 Times in 117 Posts
    Blog Entries
    4

    Default

    Hey k12onos, if you want us to post some actual code, to help get you started, could you please define whether you want a live counter (javascript) an overall time it took (php) or both.

  7. #7
    Join Date
    Aug 2006
    Posts
    58
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default

    Hi, thank you for you replies, I'm sorry for the late response.

    Actually I have done some research but unfortunately I couldn't find the javascript countdown you mentioned.

    But, I managed to find something with PHP that serves the basic function that I am searching.

    I use this in my starting page

    Code:
    <?php $timestart=time(); ?>
    
    	<input type="hidden" name="timestart" value="<?echo $timestart; ?>">
    And this in my results page

    Code:
    $timestart = $_POST['timestart'];
    
    $timeend=time(); 
    
    $used_time=$timeend-$timestart; 
    $used_time=date('s',$used_time);

    This is functional, but does not take account of the loading time of the page (since my quiz uses quite lots of images, loading time may vary due to user's internet speed), and thus, it puts those with slower internet at a disadvantage.



    Actually, I am more interested in the Live Counter you are talking about. Indeed it will make it more interesting

    Is this strictly only achievable through Javascript? If possible can you give me more pointers for me to make this live counter? or should I create a new thread at Javascript forum to prevent this going too much out of topic?

    Anyway, thanks a lot for the responses keyboard1333 and james438

Bookmarks

Posting Permissions

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