開始時刻をデータベースまたは外部ファイルに保存できます。次に、テストをリロードするときに、テストを開始した時刻、現在の時刻を取得し、まだ時間があるかどうかを計算する必要があります。
彼らがテストを提出するとき、あなたは同じことをチェックします。
生徒に使用する一意の PIN を提供する必要があるため、保存するときに再度検索できます。
このようなものがうまくいくかもしれません。
ページを読み込んだときに、一意の PIN を尋ねます。
$test_duration = 30; // minutes
$test_duration *= 60; // turning into sections for later use
// check if results from a PIN lookup are empty
if($pin_from_db == "") { // there no pin in the database. Student didn't start yet
$sql = "INSERT INTO example_student_table(student_id, start_time) VALUES ($student_id, " . date('U') . ")";
$start = date('U');
} else { // there was a PIN in the Database
$start = (int)$time_from_db;
}
// check if they still have time left
if($start < (date('U') + $start)) {
// let them do the test
} else {
// dont let them continue the test
}
フォームは次のようになります
<form action="processor.php" method="post">
// what ever other questions you need answered put here
<input type="hidden" name="end_time" value="<?php echo $start + $test_duration" />
</form>
次に、彼らがページを送信すると、「processor.php」は、割り当てられた時間内に送信したかどうかを確認できます
if(isset($_POST)) {
$allotment = $_POST['end_time'];
$now = date('U');
if($now <= $allotment) {
// they finished in time
} else {
// they didn't finish in time
}
}