views:

96

answers:

5

Hey guys, I'm making a quiz with a limit, I want to keep track of the time left with something other than javascript, Because with javascript the user could simply pause the timer by disabling javascript, and take as much time as they need. and when they are done they could simply turn JS back on and submit the quiz. I'm using coldfusion if this helps, thanks in advance.

+2  A: 

You should monitor both user and server side. Javascript is fine for user side, to give them an alert when they're close to running out of time, but you should also check server side when it's submitted. I'd recommend having a hidden field attached in the test that has a timestamp of the time the test was started, then when submitted you can compare the time started to time submitted to ensure they haven't exceeded their time. Never rely on client side verification only.

Edit Another alternative, as per the comments, would be to have the database where you keep their test scores timestamp the time they start the test, then when submitted the server compares the times and if they don't match they get nothing. This cuts the user completely out, including time zones, as everything compared is done by server time by the server. I'd still recommened tracking time with javascript on user side for those non-evil users that just want to know how much time they have.

Robert
Changing a hidden field is pretty easy though, too. If someone can disable and reenable js, they might also have the knowhow to change the value of a hidden field. Like `javascript:document.getElementById('timer_start').value = 'something else'` - not that I have a better idea..
hookedonwinter
Well, if you're really worried don't even rely on client side, just timestamp the database with open time, and check the time before you submit their scores. If the times don't match, then they get nothing.
Robert
That works. Yay for sneaky users.
hookedonwinter
A: 
var oReq = getXMLHttpRequest();


function getXMLHttpRequest() {
        if (window.XMLHttpRequest) {
            return new window.XMLHttpRequest;
        }
        else {
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.3.0");
            }
            catch (ex) {
                return null;
            }
        }
    }

and handle this at server side by calling method zx

function ZX(q, w, e, t) {


if (oReq != null) {
    oReq.open("GET", "XML.xml", true);
    oReq.onreadystatechange = function () {

       //work with response xml object


         alert(oReq.responseXML.getElementsByTagName("")[0].getAttribute("tag1"));
        if (oReq.readyState == 4 /* complete */) {
            if (oReq.status == 200) {
            }
        }
    };
    oReq.send();
}
else {
    window.alert("AJAX (XMLHTTP) not supported.");
}

}

wuits this got to do with anything?
Claudiu
to the downvoter:- before shotting your downvotes apply your brain at least.use gettime() to retrieve the time of the system and the time it was started. post this data and server will send adequate response.
+5  A: 

Use javascript on the client and session variables on the server side

Joelio
+2  A: 

Assuming you are using a session, I would log the time the user requested the page and the time the user has submitted the quiz. I would still use Javascript to display them the time left, but just for that.

mhitza
A: 

One approach, assuming you want your server to take action in the event that they didn't respond in time, would be to spawn a separate thread with cfthread, have it sleep the length of the quiz, and if their answers haven't been submitted, do whatever. I imagine something like..

  .. start of quiz stuff ..
  <cfthread action="run" name="quiztimer">
         <cfthread action="sleep" duration="120000" />
         <cfquery>fetch quiz results</cfquery>
         <cfif NoQuizAnswers>
                 <cfinsert>insert failure into quiz results</cfinsert>
         </cfif>
  </cfthread>
lazyconfabulator