<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

ob_start(); // Tambahkan ini di baris pertama

// Pastikan folder sesi buatan sendiri
$session_path = __DIR__ . '/../storage/sessions';
if (!is_dir($session_path)) {
    mkdir($session_path, 0755, true);
}
session_save_path($session_path);


// Atur waktu kedaluwarsa session menjadi 24 jam (86400 detik)
ini_set('session.gc_maxlifetime', 86400);
session_set_cookie_params(86400);
session_start();

// Tambahkan header Content Security Policy
header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; base-uri 'self'; form-action 'self'; frame-ancestors 'none';");

// Jika user tidak aktif selama 24 jam, hapus session
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 86400)) {
    session_unset();
    session_destroy();
}
$_SESSION['LAST_ACTIVITY'] = time(); // Perbarui waktu aktivitas terakhir


require_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../core/App.php';
require_once __DIR__.'/../core/Router.php';
require_once __DIR__.'/../core/Route.php';

$app = new Core\App();
