<?php
/**
 * =====================================================
 * SIMPAS v1.0
 * Session & Login Checker
 * =====================================================
 */

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

// Jika belum login
if (!isset($_SESSION['login'])) {

    header("Location: ../../login.php");
    exit();

}

// Cek timeout (opsional)
$timeout = 60 * 60 * 4; // 4 jam

if (isset($_SESSION['LAST_ACTIVITY'])) {

    if ((time() - $_SESSION['LAST_ACTIVITY']) > $timeout) {

        session_unset();
        session_destroy();

        header("Location: ../../login.php?expired=1");
        exit();

    }

}

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