<?php
// 認証共通処理
define('CLIENT_PASSWORD', 'beet');
define('ADMIN_PASSWORD', 'adm');

function startSession() {
    if (session_status() === PHP_SESSION_NONE) {
        session_start();
    }
}

function isClientAuthenticated(): bool {
    startSession();
    return isset($_SESSION['auth']) && ($_SESSION['auth'] === 'client' || $_SESSION['auth'] === 'admin');
}

function isAdminAuthenticated(): bool {
    startSession();
    return isset($_SESSION['auth']) && $_SESSION['auth'] === 'admin';
}

function requireClientAuth(): void {
    startSession();
    if (!isClientAuthenticated()) {
        header('Location: index.php');
        exit;
    }
}

function requireAdminAuth(): void {
    startSession();
    if (!isAdminAuthenticated()) {
        header('Location: admin.php');
        exit;
    }
}
