MCQ页面刷新会产生问题 [英] MCQ page refresh creates problem

查看:151
本文介绍了MCQ页面刷新会产生问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在完成一个基于MCQ的考试网站,该网站包含以下数据库:

I am finishing up with an MCQ based exam website which contains a database as under:

Qnum   Ques     Op1     Op2     Op3     Op4     Correct_answer
--------------------------------------------------------
1      blabla   aaa     bbb     ccc     ddd     Op1
2      eeeeee   fff     ggg     hhh     hhh     Op1


注意:实际上,正确答案字段的值存储为通过md5()编码的形式.

我想检查一下用户是否单击了提交"按钮,或者他刷新了页面,以便决定是应该提取下一个问题还是应该重新显示当前问题.
使用以下代码,我已经检查了这一点:


Note: In reality, the values of correct answer field are stored as encoded through md5();

I want to keep a check whether user clicked submit button or he refreshed the page so as to decide whether the next question should be fetched or the current question should be redisplayed.
With the following code, I have checked this:

$RequestSignature = md5($_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING'].print_r($_POST, true));
  if(isset($_SESSION['LastRequest']) && $_SESSION['LastRequest'] == $RequestSignature)
  {
   $_SESSION['reqstat']='refresh';
       echo '<script>alert("This was a refresh")</script>';
  }
  else
  {
    $_SESSION['qnum'] = $_SESSION['qnum']+1;
    //$_SESSION['md5v'] = $_POST['ans'];
    if($_POST['ans'] == "op1")
    {
     echo '<script>alert("Its East")</script>';
     $v = "Op1";
     if(md5($v) == $_POST['hids'])
     {
      $_SESSION["trueans"]=$_SESSION["trueans"]+1;
     }
    }
    if($_POST['ans'] == "op2")
    {
     echo '<script>alert("Its West")</script>';         
     $v = "Op2";
     if(md5($v) == $_POST['hids'])
     {
      $_SESSION["trueans"]=$_SESSION["trueans"]+1;
     }
    }
    if($_POST['ans'] == "op3")
    {
     echo '<script>alert("Its North")</script>';            
     $v = "Op3";
     if(md5($v) == $_POST['hids'])
     {
      $_SESSION["trueans"]=$_SESSION["trueans"]+1;
     }
    }
    if($_POST['ans'] == "op4")
    {
     echo '<script>alert("Its South")</script>';            
     $v = "Op4";
     if(md5($v) == $_POST['hids'])
     {
      $_SESSION["trueans"]=$_SESSION["trueans"]+1;
     }
    }
    $_SESSION['reqstat']='newrequest';
    $_SESSION['LastRequest'] = $RequestSignature;
  }



问题:
由于两个问题都具有相同的选项,因此在尝试跳至问题3时,每次都会计入页面刷新.我认为这是因为从Qnum 1跳到Qnum2时,正确答案是Op1,然后从Qnum 2跳到Qnum 3时,正确答案也是Op1.这意味着请求签名是匹配的,因此被视为刷新.

我该如何解决?

我尝试过的事情:



Problem:
Since both questions have same options, on trying to goto question 3, everytime, page refresh is counted. I think this is because on jumping from Qnum 1 to Qnum2, correct answer is Op1 and then on jumping from Qnum 2 to Qnum 3, again correct answer is Op1. Which means the request signatures are matching so it is counted as a refresh.

How can I resolve this?

What I have tried:

if(isset($_SESSION['LastRequest']) && $_SESSION['LastRequest'] == $RequestSignature  !isset($_POST['submit']))
{

}


但这总是可以继续工作,因为仍然会计算上一个问题的回发.


But this keeps on working always because the previous question''s postback is still counted.

推荐答案

RequestSignature = md5(
RequestSignature = md5(


_SERVER [' REQUEST_URI'].
_SERVER['REQUEST_URI'].


_SERVER [' QUERY_STRING'].print_r(
_SERVER['QUERY_STRING'].print_r(


这篇关于MCQ页面刷新会产生问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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