<?php
// File: api/check_session.php
require_once '../config/auth.php';

header('Content-Type: application/json');

if (!isLoggedIn()) {
    echo json_encode(['valid' => false, 'message' => 'Not logged in']);
    exit;
}

// Check session timeout (10 minutes)
$timeout = 10 * 60; // 10 minutes in seconds
$last_activity = $_SESSION['last_activity'] ?? time();

if (time() - $last_activity > $timeout) {
    // Session expired
    session_destroy();
    echo json_encode(['valid' => false, 'message' => 'Session expired']);
} else {
    // Update last activity
    $_SESSION['last_activity'] = time();
    echo json_encode(['valid' => true, 'message' => 'Session valid']);
}
?>