27 lines
648 B
PHP
27 lines
648 B
PHP
<?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;
|
|
}
|