Network_ninja Posted November 17, 2011 Share Posted November 17, 2011 Can someone show me the way? I am creating a online examination with time pressured. For example Part I of examination is only good for 20 mins. now if 20 mins is over it will be lock or good as submit. How will I do that? tnx everyone. Quote Link to comment https://forums.phpfreaks.com/topic/251299-php-timer/ Share on other sites More sharing options...
gizmola Posted November 17, 2011 Share Posted November 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251299-php-timer/#findComment-1288877 Share on other sites More sharing options...
Network_ninja Posted November 17, 2011 Author Share Posted November 17, 2011 ok. i understand ur advice. but how will i do it that there is a clock showing or a countdown timer and automatically locks the question sets after time expire? Quote Link to comment https://forums.phpfreaks.com/topic/251299-php-timer/#findComment-1288880 Share on other sites More sharing options...
gizmola Posted November 17, 2011 Share Posted November 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251299-php-timer/#findComment-1289036 Share on other sites More sharing options...
Network_ninja Posted November 18, 2011 Author Share Posted November 18, 2011 The serverside scripts will need to check to make sure that time has expired everytime it is called to accept answer data. what wud be the best ideal time to check? i am thinking if it is a good idea to run a serverside scripts to every seconds to check if time already expire? Quote Link to comment https://forums.phpfreaks.com/topic/251299-php-timer/#findComment-1289156 Share on other sites More sharing options...
gizmola Posted November 18, 2011 Share Posted November 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251299-php-timer/#findComment-1289393 Share on other sites More sharing options...
cwsmith Posted November 19, 2011 Share Posted November 19, 2011 I like gizmola's idea of saving the start time and validating the time of other answers to see if the limit has passed. Quote Link to comment https://forums.phpfreaks.com/topic/251299-php-timer/#findComment-1289469 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.