-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.php
More file actions
52 lines (44 loc) · 1.66 KB
/
Copy pathrouter.php
File metadata and controls
52 lines (44 loc) · 1.66 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
<?php
session_start();
// Vérification de la session utilisateur
$is_logged_in = isset($_SESSION['user_id']);
$is_admin = isset($_SESSION['role']) && $_SESSION['role'] === 'admin';
// Récupération et nettoyage de l'URI demandée
$request_uri = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
// Forcer la suppression des éventuels espaces et nettoyer les buffers de sortie
ob_start();
// Si aucune route n'est spécifiée ou si c'est "index", rediriger vers la page principale
if ($request_uri === '' || $request_uri === 'index') {
header("Location: /backend/views/index.php");
ob_end_flush();
exit();
}
// Vérification si c'est un fichier statique (CSS, JS, images)
$file_path = __DIR__ . '/' . $request_uri;
if (file_exists($file_path) && is_file($file_path)) {
return false;
}
// Définition des routes accessibles
$routes = [
'login' => 'backend/views/login.php',
'logout' => 'backend/views/logout.php',
'dashboard-user' => 'backend/views/dashboard-user.php',
'dashboard-admin' => 'backend/views/dashboard-admin.php',
'about' => 'backend/views/about.php',
'help' => 'backend/views/help.php',
'faq' => 'backend/views/faq.php',
'contact' => 'backend/views/contact.php',
'terms' => 'backend/views/terms.php',
'privacy' => 'backend/views/privacy.php',
];
// Vérification et inclusion des fichiers de vue
if (array_key_exists($request_uri, $routes)) {
require_once __DIR__ . '/' . $routes[$request_uri];
ob_end_flush();
exit();
}
// Si la route est invalide, rediriger vers la page principale **avec arrêt immédiat**
header("Location: /backend/views/index.php", true, 302);
ob_end_flush();
exit();
?>