-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadditioncheckanswer.php
More file actions
66 lines (60 loc) · 1.82 KB
/
additioncheckanswer.php
File metadata and controls
66 lines (60 loc) · 1.82 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require_once('additiongame.php');
require_once('config.php');
require_once('files.php');
//get info passed by last page
$arr = prepare_query_string();
//if correct method, check answer
if($arr['method']==1){
check_answer($arr['answer'], $arr['username']);
}
//check answer and redirect appropriately
function check_answer($right_answer, $username){
session_start();
increment_num_probs_attempted(ADDPROGRESSFILE, $username);
//increase total question count by 1
if(isset($_SESSION['add_total'])){
$_SESSION['add_total']++;
}
else{
$_SESSION['add_total']=1;
}
//extract user answer
$user_answer= $_POST["digitplace"];
if($user_answer==$right_answer){
increment_num_probs_correct(ADDPROGRESSFILE, $username);
//increase correct question count by 1
if(isset($_SESSION['add_correct'])){
$_SESSION['add_correct']++;
}
else{
$_SESSION['add_correct']=1;
}
$_SESSION['burger_image']++;
//go to correct answer page if haven't won, or to win screen if have
if($_SESSION['add_correct']<POINTS_TO_WIN){
header("Location: addition_right_answer.php");
}
else{
increment_num_games_won(ADDPROGRESSFILE, $username);
header("Location: addition_won_game.php");
}
}
else{
//go to incorrect answer page
header("Location: addition_wrong_answer.php?correct_answer=$right_answer");
}
}
//get info passed by last page
function prepare_query_string(){
$re = [];
$query_array = explode("&", $_SERVER["QUERY_STRING"]);
if(!empty($query_array[0])){
foreach ($query_array as $key => $value) {
$temp = explode("=", $value);
$re[$temp[0]] = $temp[1];
}
}
return $re;
}
?>