[OT] programming question

David Precious davidp at preshweb.co.uk
Thu Apr 26 13:25:03 BST 2007

Nicholas Clark wrote:
> On Thu, Apr 26, 2007 at 09:30:36AM +0100, David Precious wrote:
>> Nicholas Clark wrote:
>>> Say I'm trying to write a web based quiz. Multiple guess.
>>> What I think I want to do is have my backend take the list of possible 
>>> answers
>>> and display them in random order. My HTML form has $n radio buttons, with 
>>> $n
>>> form parameter options, and (obviously) only one is correct.

>> How are you storing the questions/answers? 
> Currently a text file, question then 5 answers.

> I think that how I store them is irrelevant here, providing that the
> constraint holds that I don't want to assign answers individual IDs,
> and I don't particularly want to have to manually randomise each question's
> answers' master order. Which ends up with "a particular master order number
> is correct" which for the sake of argument is 1. So the flag currently is
> "1".

Fair one.

  > But as I see it, whatever happens storage side if I present the 
answers in
> randomised order, and I also don't wish to maintain sessions or store
> server-side state across each and every question issued, then I have to have
> some way of remembering client side what order I presented questions in the
> client, without the client being able to trivially reverse it out. (I can
> verify that the client passes back something truthful by also saving a hash
> my-secret-appended-to-the-client-state - that's not really a problem)

Could you just have the client send back the answer as the value, then 
check whether that answer matches the first answer in the file for that 

So, HTML output looking like:

<input type="radio" name="answer" value="Answer one">Answer one <br />
<input type="radio" name="answer" value="Answer two">Answer two <br />
<input type="radio" name="answer" value="A camel">A camel <br />

You can randomise them no problems, and if the answer you get back as 
the value of the answer param matches the first answer in the file, it's 
correct.  That way, the only way to know what the correct answer is, is 
to, er, know the correct answer :)

Might be a tad simplistic (and might perhaps choke if the client's 
browse modifies the answer in subtle ways, perhaps through dodgy HTML 
encoding or something), and probably is only going to be useful if the 
answers will always be short and simple (not paragraphs of text/HTML) 
but might well do the trick?


Dave P

More information about the london.pm mailing list