在线考试系统的计时器存储每个单独部分的时间 [英] Timer for online examination system to stores the time for each individual section

查看:140
本文介绍了在线考试系统的计时器存储每个单独部分的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在线考试,我需要在整个考试期间显示一个倒数计时器/时钟。同时显示最终结果时,解决每个单独问题所需的时间也应该与测试所花费的总时间一起显示。

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

 <?php 

$ countfile =counter.txt;

//网站统计信息的位置。
$ statsfile =stats.txt;

//检查文件是否存在,如果不存在,则服务器将创建它。
if(file_exists($ countfile)){

//打开计数器命中文件。
$ fp = fopen($ countfile,r);

//读取计数器命中文件并获取文件的大小。
$ output = fread($ fp,filesize($ countfile));

//关闭计数器命中文件。
fclose($ fp);

//获取变量的整数值。
$ count = intval($ output);
}

//如果文件不存在,服务器将创建计数器命中文件并给出零值。
else {
$ count = 0;
}

// showcount函数从这里开始。
函数ShowCount(){

//声明全局变量。
global $ ShowCount,$ countfile,$ statsfile,$ count;

//获取当前月份。
$ month = date('m');

//获取当前日期。
$ day = date('d');

//获取当前年份。
$ year = date('Y');

//获取当前小时。
$ hour = date('G');

//获取当前分钟。
$分钟=日期('i');

//获得当前秒数。
$ second = date('s');

//这是统计文件中使用的日期
$ date =$ month / $ day / $ year $ hour:$ minute:$ second;

//这是用户的远程IP地址。
$ remoteip = getenv(REMOTE_ADDR);

//用户的一些浏览器详细信息。
$ otherinfo = getenv(HTTP_USER_AGENT);

//检索用户在访问当前文件之前访问的最后一个URL。
$ ref = getenv(HTTP_REFERER);

//打开统计文件。
$ fp = fopen($ statsfile,a);

//将给定的数据放入统计文件中。
fputs($ fp,远程地址:$ remoteip |);
fputs($ fp,信息:$ otherinfo |);
fputs($ fp,Date:$ date |);
fputs($ fp,Referer:$ ref \\\
);

//关闭统计文件。
fclose($ fp);

//向计数器命中文件添加1个计数。
$ count ++;

//打开计数器命中文件。
$ fp = fopen($ countfile,w);

//在柜台点击文件中写入。
//如果值是34,它将被改为35.
fwrite($ fp,$ count);

//关闭计数器命中文件。
fclose($ fp);

// showcount变量等于计数变量。
$ ShowCount = $ count;

//将count变量的值返回到showcount变量中。
返回$ ShowCount;
}

//显示计数器命中文件中的值。
echo showcount(),访问;

?>

我正在使用此脚本来跟踪访问者的统计信息和访问时间......它工作正常。但是我无法跟踪每个考试类别中的单个问题的时间(每个考试有多个类别有多个问题)。需要帮助

解决方案

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

 <?php 
//开始部分
session_start();
$ _SESSION ['TIMER'] = time()+ 600; //给用户十分钟
?>

不要在页面重新加载时执行此操作,因为它们只是刷新页面并重置计时器



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

 <脚本类型= 文本/ JavaScript的 > 
var TimeLimit = new Date('<?php echo date('r',$ _SESSION ['TIMER'])?>>');
< / script>

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

 < script type =text / javascript> 
函数countdownto(){
var date = Math.round((TimeLimit-new Date())/ 1000);
var hours = Math.floor(date / 3600);
日期=日期 - (小时* 3600);
var mins = Math.floor(date / 60);
日期=日期 - (分钟* 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>


I am developing an online examination for which i need to have a countdown timer/clock to be displayed during the entire duration of the test. Also while displaying the final result the time taken to solve each individual questions should also be displayed along with the total time taken for the test.

What are the possible best approaches to implement this functionality??

<?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";

?> 

I am using this script to track the visitor stats and time of visit...it is working fine.however I am not able to track the time of individual question in each category of the exam (each exam has multiple categories having multiple questions). Need help

解决方案

Using a session, you'll need to track when the user's time expires for the section

<?php
// Upon starting the section
session_start();
$_SESSION['TIMER'] = time() + 600; // Give the user Ten minutes
?>

Dont do that on page reload though because they can simply refresh the page and reset the timer

On the page, use Javascript to display a clock:

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

You can then use the variable 'TimeLimit' to display a countdown

<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>

这篇关于在线考试系统的计时器存储每个单独部分的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆