-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.php
More file actions
59 lines (52 loc) · 1.1 KB
/
session.php
File metadata and controls
59 lines (52 loc) · 1.1 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
<?php
include_once "./utils/no-warning.php";
include_once "./utils/string.php";
include_once "./utils/user.php";
include_once "./utils/db.php";
session_start();
function LogOut()
{
$unset = session_unset();
$destroyed = session_destroy();
if ($unset && $destroyed)
{
header("Location: ./index.php");
exit;
}
RedirectToError('Impossibile effettuare il logout!');
}
function LogIn(User $user)
{
$_SESSION['user_id'] = $user->ID;
$_SESSION['admin'] = $user->Admin;
RedirectToHome();
}
function IsLoggedIn()
{
$user_id = $_SESSION['user_id'];
return !isEmpty($user_id);
}
function RedirectToLogin()
{
header("Location: ./login.php");
exit;
}
function RedirectToError(string $err = "")
{
if (isEmpty($err))
header("Location: ./error.php");
else
header("Location: ./error.php?err=" . urlencode($err));
exit;
}
function RedirectToHome()
{
header('Location: ./me.php');
exit;
}
if (!IsLoggedIn() && !isset($DO_NOT_CHECK_LOGIN))
{
RedirectToLogin();
}
$USER_ID = $_SESSION['user_id'];
$IS_ADMIN = $_SESSION['admin'];