-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-router.php
More file actions
82 lines (52 loc) · 1.96 KB
/
admin-router.php
File metadata and controls
82 lines (52 loc) · 1.96 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
function isAdminAuthenticated() {
return isset($_SESSION['admins_id']);
}
$request_uri = strtok($_SERVER['REQUEST_URI'], '?');
switch (true) {
case preg_match('#^/admin/login/?$#', $request_uri):
if (isAdminAuthenticated()) {
header('Location: /admin');
exit;
}
include __DIR__ . '/admin/login.php';
break;
case preg_match('#^/admin/pages/([a-zA-Z0-9-_]+)$#', $request_uri, $matches):
if (!isAdminAuthenticated()) {
http_response_code(401);
echo 'Authentication required.';
exit;
}
$page = $matches[1];
$page_file = __DIR__ . '/admin/pages/' . $page . '.php';
$allowed_pages = [
'dashboard', 'view-ads', 'pending-ads', 'reported-ads', 'category', 'add-ad-category', 'sub-cat',
'view-blogs', 'pending-blogs', 'blog-cat', 'view_users',
'view-subscribers', 'send-newsletter', 'site-settings', 'email-settings',
'security-roles', 'analytics', 'backup-restore', 'export-data'
];
if (in_array($page, $allowed_pages) && file_exists($page_file)) {
include $page_file;
} else {
http_response_code(404);
echo 'Page content not found.';
}
break;
case preg_match('#^/admin(/([a-zA-Z0-9-_]+))?/?$#', $request_uri, $matches):
if (!isAdminAuthenticated()) {
header('Location: /admin/login');
exit;
}
$page = $matches[2] ?? 'dashboard';
$_GET['page'] = $page;
include __DIR__ . '/admin/admin-page.php';
break;
default:
http_response_code(404);
include __DIR__ . '/admin/pages/404.php';
break;
}
?>