2011-09-09 41 views
-2

我想知道如何设置秒表并防止他agaist作弊。 我打算用如何在测试评估期间保护秒表?

  • date()
  • $_SERVER['DATE_GMT']
  • $_SERVER['DATE_LOCAL']

但我不知道这是否是一个很好的方法,如果我是很好的方式。

时间结束后,测试评估必须反对修改(endof测试),并且我想检查是否$end_test = $end_planned这是$start_test + 60min

回答

2

您可以将开始的时间存储在数据库或外部文件中。然后,当他们重新加载测试时,你需要得到他们开始测试的时间,当前时间,并计算他们是否还有时间。

当他们提交测试时,你会检查同样的事情。

你必须给学生一个独特的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 
    } 
}