<?php

$tokenDir  = __DIR__ . '/token';
$tokenFile = $tokenDir . '/file.txt';

// cookie token
$cookieToken = $_COOKIE['admin_token'] ?? null;

// basic checks
if (!$cookieToken || !file_exists($tokenFile)) {
    header("Location: expired.php");
    exit;
}

// read token file
$data = json_decode(file_get_contents($tokenFile), true);

if (
    !$data ||
    !isset($data['token'], $data['expiry'])
) {
    header("Location: expired.php");
    exit;
}

// expiry check
if (time() > $data['expiry']) {
    header("Location: expired.php");
    exit;
}

// token match check
if (!hash_equals($data['token'], $cookieToken)) {
    header("Location: expired.php");
    exit;
}
require_once __DIR__ . '/../conn.php';
require_once __DIR__ . '/../functions.php';

// admin/auth.php


// ✅ AUTH PASSED
// page execution continues


?>