I am coding a web based exam application in PHP.
- The examinee has to choose a set of modules with the according questions.
- A module is represented as one-single-formular.
- For each module he got for example 30 minutes.
I will achive that if the 30 minutes are over, the state of the form
(answered and unanswered questions will be stored in a database) and the
form will be closed e.g. redirect to menu page. I tried something like
that:
PHP :
<?php
set_time_limit('30000');
function redirect(){
// Some Stuff
}
$i = 1;
while($i <= 45){
sleep('60');
callthis();
flush();
$i++;
}
?>
At my hoster set_time_limit couldn’t be used because of PHP’s Safe Mode.
What is the most reliable server-based solution (no Javascript) for a form
timer in PHP?
Here’s a simple method
When the form is submitted you simply need to check the token was generated in the last 30 minutes. You can implement some client side countdown as an aid to the user, but the real timing must happen on the server side.
You would need to add a few additional security checks and balances, such as ensuring a logged in user can only have one token at any one time.