Jump to content

Php Timer


Network_ninja

Recommended Posts

I would personally have a database structure where I had rows that indicated the start time of a section of an exam.  You can store the time easily using a datetime or timestamp column.  When a section is begun, you set the value of this column in a query to NOW().

 

When a new answer is submitted, you can utilize date arithmetic to determine if they have passed the allocated amount of time, and decide if the answer should be accepted or not.

 

You can also use session variables and in recent versions of php there is the datetime object that is very useful and has many functions that facilitate an elapsed time calculation.

Link to comment
Share on other sites

You can use javascript to implement an onscreen countdown timer based on the same date/time.  To do this with any level of competency, you will need to use ajax, so that you can accept answers immediately without having to do a complete form refresh.

 

I would highly recommend learning how to use jquery, which can facilitate the ajax and provide you functions that can help insure the clock will work across different browsers and versions.  The important thing to keep in mind is that the javascript timer has to be for display purposes only -- you can not depend on it, as it runs in the user's browser.  The serverside scripts will need to check to make sure that time has expired everytime it is called to accept answer data.

 

This is a non-trivial question, and I can only provide you general answers.  You'll have to research the specifics.

Link to comment
Share on other sites

What I would do is have the javascript clock based on the timestamp of the section row you create in the database, that indicates the user has started the form. 

 

Once the clock is running there is no reason to worry about checking it -- it should keep time acceptably.

 

When a question is submitted you simply need to check if the allowed time has expired, and handle that accordingly.  Return a result that indicates the time has expired, and close out the section of the test. That same routine should be fired when the javascript clock expires.

 

If someone is sneaky enough to figure out how to modify the runtime value of your original variable, the serverside script will still catch them.  That is all you are really concerned about.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.