-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
77 lines (70 loc) · 2.21 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
session_start();
require __DIR__ . '/includes/utils.php';
require __DIR__ . '/includes/DBConnection.php';
require __DIR__ . '/includes/QueryManager.php';
require __DIR__ . '/includes/UserInfo.php';
define('PRODUCTION_PATH_PREFIX', '/~alfrol/prax4/');
define('PATH_PREFIX', '/');
$redirect = '';
// Handle the case when additional query parameters are passed.
if (strpos($_SERVER['REQUEST_URI'], '?')) {
$url_parts = explode('?', $_SERVER['REQUEST_URI']);
$redirect = $url_parts[0];
QueryManager::handle_query($url_parts[1]);
} else {
$redirect = $_SERVER['REQUEST_URI'];
}
$db = new DBConnection();
$ui = new UserInfo();
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin']) {
switch ($redirect) {
case '':
case PATH_PREFIX:
case PATH_PREFIX . 'login':
case PATH_PREFIX . 'register':
header('Location: home');
break;
case PATH_PREFIX . 'home':
require __DIR__ . '/pages/home.php';
break;
case PATH_PREFIX . 'profile':
require __DIR__ . '/pages/profile.php';
break;
case PATH_PREFIX . 'profile-info':
require __DIR__ . '/pages/profile_info.php';
break;
case PATH_PREFIX . 'new-switt':
require __DIR__ . '/pages/new_switt.php';
break;
case PATH_PREFIX . 'search':
require __DIR__ . '/pages/search.php';
break;
default:
http_response_code(404);
require __DIR__ . '/pages/404.php';
break;
}
} else {
switch ($redirect) {
case '':
case PATH_PREFIX:
case PATH_PREFIX . 'home':
case PATH_PREFIX . 'profile':
case PATH_PREFIX . 'profile-info':
case PATH_PREFIX . 'new-switt':
case PATH_PREFIX . 'search':
header('Location: login');
break;
case PATH_PREFIX . 'login':
require __DIR__ . '/pages/login.php';
break;
case PATH_PREFIX . 'register':
require __DIR__ . '/pages/register.php';
break;
default:
http_response_code(404);
require __DIR__ . '/pages/404.php';
break;
}
}