首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于在线考试系统的定时器,用于存储每个单独部分的时间

用于在线考试系统的定时器,用于存储每个单独部分的时间
EN

Stack Overflow用户
提问于 2012-01-11 16:18:29
回答 2查看 18.5K关注 0票数 2

我正在开发一个在线考试,我需要有一个倒计时计时器/时钟显示在整个测试期间。此外,在显示最终结果的同时,还应显示解决每个单独问题所用的时间以及测试所用的总时间。

实现此功能的最佳方法可能是什么?

代码语言:javascript
复制
<?php

$countfile = "counter.txt";

// location of site statistics.
$statsfile = "stats.txt";

// checks whether the file exist, if not then server will create it.
if (file_exists($countfile)) {

// open the counter hit file.
$fp = fopen($countfile, "r"); 

// reads the counter hit file and gets the size of the file.
$output = fread($fp, filesize($countfile));

// close the counter hit file.
fclose($fp); 

// get the integer value of the variable.
$count = intval($output);
}

// if file is doesn't exist, the server will create the counter hit file and gives a value of zero.
else { 
$count = 0;
}

// showcount function starts here.
function ShowCount() { 

// declares the global variables.
global $ShowCount, $countfile, $statsfile, $count;

// get the current month.
$month = date('m');

// get the current day.
$day = date('d');

// get the current year.
$year = date('Y');

// get the current hour.
$hour = date('G');

// get the current minute.
$minute = date('i');

// get the current second.
$second = date('s');

// this is the date used in the stats file
$date = "$month/$day/$year $hour:$minute:$second";

// this is the remote IP address of the user.
$remoteip = getenv("REMOTE_ADDR");

// some of the browser details of the user.
$otherinfo = getenv("HTTP_USER_AGENT");

// retrieve the last URL where the user visited before visiting the current file.
$ref = getenv("HTTP_REFERER");

// open the statistics file. 
$fp = fopen($statsfile, "a");

// put the given data into the statistics file.
fputs($fp, "Remote Address: $remoteip | ");
fputs($fp, "Information: $otherinfo | ");
fputs($fp, "Date: $date | ");
fputs($fp, "Referer: $ref\n");

// close the statistics file.
fclose($fp);

// adds 1 count to the counter hit file.
$count++;

// open the counter hit file.
$fp = fopen($countfile, "w");

// write at the counter hit file.
// if the value is 34, it will be changed to 35.
fwrite($fp, $count);

// close the counter hit file.
fclose($fp);

// showcount variable is equal to count variable.
$ShowCount = $count;

// return the value of the count variable into showcount variable.
return $ShowCount;
}

// display the value in the counter hits file.
echo showcount(), " visits";

?> 

我使用这个脚本来跟踪访问者统计数据和visit...it的工作时间fine.however我无法跟踪每个考试类别中单个问题的时间(每个考试都有多个类别,有多个问题)。需要帮助

EN

回答 2

Stack Overflow用户

发布于 2012-01-11 16:42:58

使用会话时,您需要跟踪该部分的用户时间何时到期

代码语言:javascript
复制
<?php
// Upon starting the section
session_start();
$_SESSION['TIMER'] = time() + 600; // Give the user Ten minutes
?>

不要在页面重新加载时这样做,因为他们可以简单地刷新页面并重置计时器

在页面上,使用Javascript显示时钟:

代码语言:javascript
复制
<script type="text/javascript">
var TimeLimit = new Date('<?php echo date('r', $_SESSION['TIMER']) ?>');
</script>

然后,您可以使用变量'TimeLimit‘显示倒计时

代码语言:javascript
复制
<script type="text/javascript">
function countdownto() {
  var date = Math.round((TimeLimit-new Date())/1000);
  var hours = Math.floor(date/3600);
  date = date - (hours*3600);
  var mins = Math.floor(date/60);
  date = date - (mins*60);
  var secs = date;
  if (hours<10) hours = '0'+hours;
  if (mins<10) mins = '0'+mins;
  if (secs<10) secs = '0'+secs;
  document.body.innerHTML = hours+':'+mins+':'+secs;
  setTimeout("countdownto()",1000);
  }

countdownto();
</script>
票数 3
EN

Stack Overflow用户

发布于 2012-01-11 16:35:43

您可以通过执行以下操作来实现此目的

当学生开始考试时,在一些store/database.

  • To中存储
  1. StartTime进行倒计时,你可以在客户端使用javascript。写一个函数,它将需要2次,第一次将是服务器时间,第二次将是StartTime。使用这些方法,你可以找出候选人解决问题的时间,并且从中你可以找出剩余的时间。使用candidate.
  2. Add的setInterval,您可以显示滴答表。
  3. 用于解决问题所用的时间,存储对javascript可见问题的持续时间单个问题所用的时间,并显示总时间。

我猜这就是你要找的答案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8816158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档