-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
39 lines (32 loc) · 1.01 KB
/
config.php
File metadata and controls
39 lines (32 loc) · 1.01 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
<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'visitor_db');
define('DB_USER', 'root');
define('DB_PASS', '');
try {
$pdo = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4", DB_USER, DB_PASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
error_log("Database connection error: " . $e->getMessage());
die("Internal Server Error. Please contact admin.");
}
session_start();
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
function validateCsrf($token) {
return isset($token) && hash_equals($_SESSION['csrf_token'], $token);
}
function checkAuth() {
if (!isset($_SESSION['user_id'])) {
header("Location: index.php");
exit;
}
}
function isAdmin() {
return isset($_SESSION['role']) && $_SESSION['role'] === 'admin';
}
function isGuard() {
return isset($_SESSION['role']) && ($_SESSION['role'] === 'guard' || $_SESSION['role'] === 'admin');
}
?>