<?php
// Proteção simples para área admin (sessão)

function admin_is_logged(): bool {
  return isset($_SESSION['admin_user']) && is_array($_SESSION['admin_user']);
}

function admin_require_login(): void {
  if (!admin_is_logged()) {
    header('Location: login.php');
    exit;
  }
}

function admin_logout(): void {
  $_SESSION = [];
  if (ini_get('session.use_cookies')) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
      $params['path'], $params['domain'],
      $params['secure'], $params['httponly']
    );
  }
  session_destroy();
}
