<?php

$timeout = 14400; // 4 jam

ini_set('session.gc_maxlifetime', $timeout);
ini_set('session.cookie_lifetime', $timeout);

session_start();

if (!isset($_SESSION['login'])) {
    header("Location: login.php?error=noakses");
    exit;
}

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

    session_unset();
    session_destroy();
    header("Location: login.php?error=timeout");
    exit;
}

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