| 12345678910111213141516171819202122232425262728 |
- <?php
- // auth.php – shared admin authentication helper
- // Include at the top of every admin page.
- require_once __DIR__ . '/../db.php';
- session_name('packit_admin');
- session_start();
- define('ADMIN_LOGGED_IN', isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true);
- function require_admin(): void {
- if (!ADMIN_LOGGED_IN) {
- header('Location: ' . admin_url('login.php'));
- exit;
- }
- }
- function admin_url(string $page): string {
- return $page;
- }
- function admin_logout(): void {
- $_SESSION = [];
- session_destroy();
- header('Location: login.php');
- exit;
- }
|