-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.php
45 lines (34 loc) · 1014 Bytes
/
index.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
<?php
require_once __DIR__ . "/database/database_connection.php";
require_once __DIR__ . "/resources/lib/php_functions.php";
//we get the request url and store it in a variable $request_site
$request_site = isset($_GET['request_site']) ? $_GET['request_site'] : 'home';
session_start();
if ($request_site === "logout") {
session_destroy();
header("Location: login");
exit();
}
$logged_in = user();
//displaying login page
if (!$logged_in) {
$request_site = "login";
}
$path = __DIR__ . "/resources/pages/";
//path to pages
if ($logged_in) {
//we check the role of logged in user and construct link to either administrator or lecture folder
$page_path = $path . "$logged_in->role/$request_site.php";
} else {
$page_path = $path . "$request_site.php";
}
// echo $page_path;
if (file_exists($page_path)) {
require $page_path;
} else {
require "{$path}404.php";
}
// unsetting the errors after they have been displayed
if (isset($_SESSION['errors'])) {
unset($_SESSION['errors']);
}