<?php

error_reporting(0);



// Start or resume session with super admin's unique session name

if (isset($_COOKIE["session_name"])) {

    session_name($_COOKIE["session_name"]);

    session_start();

} else {

    header("Location: admin_mini.php"); // Redirect if session cookie is missing

    exit();

}



// Check if the super admin is logged in

if (!isset($_SESSION['sid']) || $_SESSION['permission'] !== 'Super User') {

    session_unset();

    session_destroy();

    header("Location: admin_mini.php");

    exit();

}



// 🔴 Auto-logout after 15 min of inactivity

$inactive = 900; // 900 seconds = 15 minutes

if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity'] > $inactive)) {

    session_unset();

    session_destroy();

    setcookie("session_name", "", time() - 3600, "/");

    header("Location: admin_mini.php?timeout=true");

    exit();

}

$_SESSION['last_activity'] = time(); // Update activity timestamp



// Regenerate session ID for security

if (!isset($_SESSION['last_regeneration'])) {

    $_SESSION['last_regeneration'] = time();

} elseif (time() - $_SESSION['last_regeneration'] > 900) {

    session_regenerate_id(true);

    $_SESSION['last_regeneration'] = time();

}



// Store session data

$adminId = $_SESSION['sid'];

$adminName = $_SESSION['name'];

$adminLastName = $_SESSION['lastname'];

$adminEmail = $_SESSION['email'];

$adminPermission = $_SESSION['permission'];


