auth.php 618 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. // auth.php – shared admin authentication helper
  3. // Include at the top of every admin page.
  4. require_once __DIR__ . '/../db.php';
  5. session_name('packit_admin');
  6. session_start();
  7. define('ADMIN_LOGGED_IN', isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true);
  8. function require_admin(): void {
  9. if (!ADMIN_LOGGED_IN) {
  10. header('Location: ' . admin_url('login.php'));
  11. exit;
  12. }
  13. }
  14. function admin_url(string $page): string {
  15. return $page;
  16. }
  17. function admin_logout(): void {
  18. $_SESSION = [];
  19. session_destroy();
  20. header('Location: login.php');
  21. exit;
  22. }