<?php
/**
 * Panel Authentication Check
 * Include this file at the top of protected pages
 */

session_start();

// Check if user is logged in
if (!isset($_SESSION['panel_logged_in']) || $_SESSION['panel_logged_in'] !== true) {
    header('Location: login.php');
    exit;
}

// Check session timeout (30 minutes)
$sessionTimeout = 1800; // 30 minutes
if (isset($_SESSION['login_time']) && (time() - $_SESSION['login_time']) > $sessionTimeout) {
    session_unset();
    session_destroy();
    header('Location: login.php?timeout=1');
    exit;
}

// Update last activity time
$_SESSION['login_time'] = time();

// Get current user
$currentUser = isset($_SESSION['panel_username']) ? $_SESSION['panel_username'] : 'Unknown';
?>
