This repository was archived by the owner on Jul 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinclude.php
More file actions
68 lines (57 loc) · 2.24 KB
/
include.php
File metadata and controls
68 lines (57 loc) · 2.24 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
<?php
// include.php
session_start();
include_once 'config.php';
include_once "functions/language-functions.php";
include_once "functions/admin-functions.php";
include_once "functions/user-functions.php";
include_once "functions/email-functions.php";
include_once "functions/pokedex-functions.php";
require_once 'vendor/phpmailer/src/Exception.php';
require_once 'vendor/phpmailer/src/PHPMailer.php';
require_once 'vendor/phpmailer/src/SMTP.php';
// Maintenance mode check
try {
// Fetch the maintenance mode setting
$stmt = $pdo->prepare("SELECT setting_value FROM site_settings WHERE setting_name = 'Maintenance Mode'");
$stmt->execute();
$maintenanceMode = $stmt->fetchColumn();
// Determine the current page
$currentPage = basename($_SERVER['PHP_SELF']);
// Allow all users access to specific pages during maintenance
$alwaysAllowedPages = ['login.php', 'maintenance.php', 'banned.php'];
// Redirect from maintenance.php if maintenance mode is OFF
if ($currentPage === 'maintenance.php' && $maintenanceMode !== 'YES') {
header("Location: index.php");
exit;
}
if ($maintenanceMode === 'YES') {
// If on an always-allowed page, let the user proceed
if (!in_array($currentPage, $alwaysAllowedPages)) {
// If the user is not logged in, redirect to login.php
if (!is_user_logged_in()) {
header("Location: login.php");
exit;
}
// If the user is logged in but not an admin, redirect to maintenance.php
if (!is_user_admin()) {
header("Location: maintenance.php");
exit;
}
}
}
// Check if the user is banned
if (is_user_logged_in() && !in_array($currentPage, $alwaysAllowedPages)) {
$stmt = $pdo->prepare("SELECT is_banned FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$isBanned = $stmt->fetchColumn();
if ($isBanned === 'YES') {
header("Location: banned.php");
exit;
}
}
} catch (PDOException $e) {
error_log("Error checking maintenance mode or ban status: " . $e->getMessage());
// Optionally, display an error message or redirect to an error page
}
?>