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

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

// Check if user is logged in
if (isset($_SESSION['username']) && !empty($_SESSION['username'])) {
    echo json_encode(['valid' => true, 'username' => $_SESSION['username']]);
} else {
    echo json_encode(['valid' => false, 'message' => 'Session expired']);
}
?>
