-
Notifications
You must be signed in to change notification settings - Fork 2
/
challenge.php
54 lines (49 loc) · 1.58 KB
/
challenge.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
50
51
52
53
54
<?php
class Challenge{
public $level;
public $title;
public $text;
public $formField;
public $hint;
public $nextUrl;
public $password;
public $solvedBy;
public function Challenge($level, $title, $text, $formField, $hint, $nextUrl, $password){
$this->level=$level;
$this->title=$title;
$this->text=$text;
$this->formField=$formField;
$this->hint=$hint;
$this->nextUrl=$nextUrl;
$this->password=$password;
$this->solvedBy=Challenge::readSolvedByFromFile($level);
}
public static function readSolvedByFromFile($file){
$myfile = fopen("leaderboard/".$file.".txt", "r") or die("Unable to open file to read!");
$solvedBy = (int)fread($myfile,filesize("leaderboard/".$file.".txt"));
fclose($myfile);
return $solvedBy;
}
public function increaseSolvedBy($file, $solvedBy){
$myfile = fopen("leaderboard/".$file.".txt", "w") or die("Unable to open file to write!");
fwrite($myfile, ($solvedBy+1));
fclose($myfile);
}
public function checkPasswordAndRedirect($trial){
if($trial == $this->password){
$this->increaseSolvedBy($this->level, $this->solvedBy);
header("Location: index.php?site=".$this->nextUrl);
die();
}
return 0; //if password was bad, otherwise already died
}
public function getLevel(){return $this->level;}
public function getTitle(){ return $this->title;}
public function getText(){ return $this->text;}
public function getFormField(){ return $this->formField;}
public function getHint(){ return $this->hint;}
public function getNextUrl(){ return $this->nextUrl;}
public function getPassword(){ return $this->password;}
public function getSolvedBy(){ return $this->solvedBy;}
}
?>