![]() |
|
Quiz Timer - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: PHP (https://sinister.ly/Forum-PHP) +--- Thread: Quiz Timer (/Thread-Quiz-Timer) |
Quiz Timer - Ex094 - 07-16-2014 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
RE: Quiz Timer - The Real Slim Shady - 07-16-2014 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? RE: Quiz Timer - zomgwtfbbq - 07-16-2014 I don't really get it...how come the time stops when the user goes offline? That's a pretty nice feature actually. ![]() 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. RE: Quiz Timer - Ex094 - 07-16-2014 (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. I meant the timer resets Well I'll see what I can do about this
RE: Quiz Timer - zomgwtfbbq - 07-16-2014 (07-16-2014, 02:16 PM)Ex094 Wrote:Are you actually storing the user's session?(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. RE: Quiz Timer - Ligeti - 07-16-2014 @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 RE: Quiz Timer - Ex094 - 07-16-2014 (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? I'm currently trying @Geoff's suggestion, Cheating won't be a big deal cuz I've already taken care of that part Was having trouble with the timer function though, I'll give ya guys a feedback in a few days... Thanks for your suggestions
RE: Quiz Timer - h3r0 - 07-16-2014 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();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) RE: Quiz Timer - zomgwtfbbq - 07-16-2014 (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..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. |