Question: MCQ Page refresh

Question

MCQ Page refresh

Answers 0
Added at 2016-12-13 09:12
Tags
Question


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

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

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?

Answers to

MCQ Page refresh

Source Show
◀ Wstecz