<?php
// Mulai session
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Load semua config utama
require_once __DIR__ . '/koneksi.php';
require_once __DIR__ . '/security.php';
require_once __DIR__ . '/functions.php';

// Autentikasi login
if (!isset($_SESSION['user_id'])) {
    header("Location: " . base_url('login.php'));
    exit;
}

// Timeout session (misal auto logout setelah 2 jam)
$max_inactive = 2 * 60 * 60; // 2 jam
if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity'] > $max_inactive)) {
    session_unset();
    session_destroy();
    header("Location: " . base_url('login.php?expired=1'));
    exit;
}
$_SESSION['last_activity'] = time();
