-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_correct_tf.php
49 lines (43 loc) · 1.07 KB
/
is_correct_tf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
*
* @param type $corrAnsIndex
* @param type $answer
* @param type $answerInput
* @return boolean
*/
function answerCheck($corrAnsIndex, $answer, $answerInput)
{
$isCorrect = false;
if ($corrAnsIndex == $answer) {
if ($answerInput == 'yes') {
$_SESSION['correctAnswersCount'] ++;
$isCorrect = true;
}
}
if ($corrAnsIndex != $answer) {
if ($answerInput == 'no') {
$_SESSION['correctAnswersCount'] ++;
$isCorrect = true;
}
}
$_SESSION['answeredQuestionsCount'] ++;
return $isCorrect;
}
/**
*
* @return type
*/
function isFinished()
{
if ($_SESSION['answeredQuestionsCount'] == $_SESSION['totalQuestionsCount']) {
$_SESSION['finishedAt'] = time();
header("Location: results.php");
}
}
$correctAnswerIndex = $_SESSION['questions']
[$_SESSION['answeredQuestionsCount']]['answer']['id'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$isCorrect = answerCheck($correctAnswerIndex, $_POST['answer'], $_POST['answer_input']);
}
isFinished();