Initial production backup
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin Authentication Middleware
|
||||
*/
|
||||
session_start();
|
||||
|
||||
require_once dirname(__DIR__) . '/config.php';
|
||||
|
||||
function isLoggedIn(): bool {
|
||||
return isset($_SESSION['blog_admin_id']) && !empty($_SESSION['blog_admin_id']);
|
||||
}
|
||||
|
||||
function requireLogin(): void {
|
||||
if (!isLoggedIn()) {
|
||||
header('Location: ' . BLOG_URL . '/admin/login.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function getAdminUser(): ?array {
|
||||
if (!isLoggedIn()) return null;
|
||||
$db = getDB();
|
||||
$stmt = $db->prepare("SELECT id, username FROM blog_admins WHERE id = :id LIMIT 1");
|
||||
$stmt->execute([':id' => $_SESSION['blog_admin_id']]);
|
||||
return $stmt->fetch() ?: null;
|
||||
}
|
||||
Reference in New Issue
Block a user