-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.class.php
42 lines (34 loc) · 1.02 KB
/
session.class.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
<?php
class Session {
private array $messages;
public function __construct() {
session_start();
$this->messages = isset($_SESSION['messages']) ? $_SESSION['messages'] : array();
unset($_SESSION['messages']);
}
public static function login() : bool {
return isset($_SESSION['id']);
}
public static function logout() {
session_destroy();
}
public static function getId() : ?int {
return isset($_SESSION['id']) ? $_SESSION['id'] : null;
}
public static function getUsername() : ?string {
return isset($_SESSION['username']) ? $_SESSION['username'] : null;
}
public function setId(int $id) {
$_SESSION['id'] = $id;
}
public function setUsername(string $username) {
$_SESSION['username'] = $username;
}
public function addMessage(string $type, string $text) {
$_SESSION['messages'][] = array('type' => $type, 'text' => $text);
}
public function getMessages() {
return $this->messages;
}
}
?>