I don't have a sample script, I'd need to write it, which I don't have time for now.
You could have one or more SESSION variables, eg. one for each question, one for the overall test.
I would store the SESSION variable in a database that has a "time" field. checked on the subsequent page and compared with "now". If "less than X" OK, else "too long".