Login Register


Quiz Timer filter_list
Author
Message
Quiz Timer #1
So I am developing an online quiz script, the user will be given a fixed interval of time to solve the quiz. Now the problem is my timer function is a little faulty, it doesn't keep on going if the user goes offline hence the user can give the test again which I don't want.

Is there any way to keep the timer running even after the user goes offline or should I save my duration time and calculate the difference, Example with code will be appreciated Smile
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Quiz Timer #2
uhm, not in the code writing mood - but this is a rather simple task no?

You store the date/time the test was started, and if they come back online, the current date/time. The difference is the amount of time that has surpassed? if its greater than what you want then show an error, otherwise show the remaining time?

Reply

RE: Quiz Timer #3
I don't really get it...how come the time stops when the user goes offline? That's a pretty nice feature actually. Biggrin

Anyway, just save the unix timestamp when the user starts and go from there. Personally I'd go for an ajax based quiz that would keep the quiz on your screen without reloading after each question was answered. After each answer you can send back some json data to load the next question or finish the quiz. You can eg use setInterval each second to check whether the time is already over. The advantage is that the user will be shown in realtime that the time is over and it's pretty much impossible to cheat. The only disadvantage would be that you send a request every x seconds to the server. But it will look much slicker.

Reply

RE: Quiz Timer #4
(07-16-2014, 12:38 PM)zomgwtfbbq Wrote: I don't really get it...how come the time stops when the user goes offline? That's a pretty nice feature actually. Biggrin

Anyway, just save the unix timestamp when the user starts and go from there. Personally I'd go for an ajax based quiz that would keep the quiz on your screen without reloading after each question was answered. After each answer you can send back some json data to load the next question or finish the quiz. You can eg use setInterval each second to check whether the time is already over. The advantage is that the user will be shown in realtime that the time is over and it's pretty much impossible to cheat. The only disadvantage would be that you send a request every x seconds to the server. But it will look much slicker.

I meant the timer resets Tongue Well I'll see what I can do about this
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Quiz Timer #5
(07-16-2014, 02:16 PM)Ex094 Wrote:
(07-16-2014, 12:38 PM)zomgwtfbbq Wrote: I don't really get it...how come the time stops when the user goes offline? That's a pretty nice feature actually. Biggrin

Anyway, just save the unix timestamp when the user starts and go from there. Personally I'd go for an ajax based quiz that would keep the quiz on your screen without reloading after each question was answered. After each answer you can send back some json data to load the next question or finish the quiz. You can eg use setInterval each second to check whether the time is already over. The advantage is that the user will be shown in realtime that the time is over and it's pretty much impossible to cheat. The only disadvantage would be that you send a request every x seconds to the server. But it will look much slicker.

I meant the timer resets Tongue Well I'll see what I can do about this
Are you actually storing the user's session?

Reply

RE: Quiz Timer #6
@Ex094 why don't you follow @Geoff's suggestion? I would add authentication maybe, so you can make sure that the user is not cheating (if it is that important for you to know)... you are not giving away money (in reward) I believe are you?

Thanks
[Image: wvBFmA5.png]

Reply

RE: Quiz Timer #7
(07-16-2014, 05:00 PM)Ligeti Wrote: @Ex094 why don't you follow @Geoff's suggestion? I would add authentication maybe, so you can make sure that the user is not cheating (if it is that important for you to know)... you are not giving away money (in reward) I believe are you?

Thanks

I'm currently trying @Geoff's suggestion, Cheating won't be a big deal cuz I've already taken care of that part Biggrin Was having trouble with the timer function though, I'll give ya guys a feedback in a few days... Thanks for your suggestions Smile
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Quiz Timer #8
The issue with having a JS timer would have to be cheating. But the method WILL be storing a unix time stamp somewhere. You could go with storing it in a PHP session..
Code:
$date = new DateTime(); $_SESSION['last_submit_time'] = $date->getTimestamp();
This allows you to use AJAX or just use PHP and when the page loads inject the $_SESSION['last_submit_time'] into the JS.

But if you were feeling a little dangerous you can do some HTML5 Web Storage which is a local database http://www.w3schools.com/html/html5_webstorage.asp
Issue with that is that it could be edited by the user.


I would suggest going the pure PHP route (No Ajax) because what if a user doesn't have Javascript. Or use Ajax and fall back onto to PHP (This is probably the best and most professional route if you plan on making this a reusable piece of software to sell)
[Image: iQ3pcQu.png]
BTC Address: 1DCKgDaWcmc9dxBkhe9qrTQtrQpoFUzXdn

Reply

RE: Quiz Timer #9
(07-16-2014, 07:10 PM)h3r0 Wrote: The issue with having a JS timer would have to be cheating. But the method WILL be storing a unix time stamp somewhere. You could go with storing it in a PHP session..
Code:
$date = new DateTime(); $_SESSION['last_submit_time'] = $date->getTimestamp();
This allows you to use AJAX or just use PHP and when the page loads inject the $_SESSION['last_submit_time'] into the JS.

But if you were feeling a little dangerous you can do some HTML5 Web Storage which is a local database http://www.w3schools.com/html/html5_webstorage.asp
Issue with that is that it could be edited by the user.


I would suggest going the pure PHP route (No Ajax) because what if a user doesn't have Javascript. Or use Ajax and fall back onto to PHP (This is probably the best and most professional route if you plan on making this a reusable piece of software to sell)
You could also make a fallback for non js users.

The possibilities of js/jquery/ajax + php will provide the user with a nicer experience in realtime. Personally I always show a message if js isn't supported or if noscript is running on the browser. I don't really care about the small percentage of users that don't have js support in their browser. Of course it's a different thing if you're building an app for a client.

Reply







Users browsing this thread: 1 Guest(s)