<?php
session_start();

header('Content-Type: text/plain');

echo "=== SESSION DIAGNOSTIC ===\n\n";

echo "1. Session Status:\n";
echo "   Session ID: " . session_id() . "\n";
echo "   Session Status: " . (session_status() === PHP_SESSION_ACTIVE ? "ACTIVE" : "INACTIVE") . "\n";
echo "   Session Save Path: " . ini_get('session.save_path') . "\n";
echo "   Session Handler: " . ini_get('session.save_handler') . "\n\n";

echo "2. Direct Session Test:\n";
$_SESSION['test_value'] = 'TEST_' . time();
session_write_close();
echo "   Set: \$_SESSION['test_value'] = 'TEST_" . time() . "'\n";
echo "   Restart session...\n";

// Restart to read value back
session_start();
echo "   Retrieved: \$_SESSION['test_value'] = '" . ($_SESSION['test_value'] ?? 'NOT FOUND') . "'\n\n";

echo "3. Language/Currency Test:\n";
$_SESSION['selected_language'] = 'it';
$_SESSION['selected_currency'] = 'eur';
session_write_close();
echo "   Set language = 'it' and currency = 'eur'\n";
echo "   Session data written and closed\n\n";

// Restart again
session_start();
echo "4. After Restart:\n";
echo "   selected_language = '" . ($_SESSION['selected_language'] ?? 'NOT FOUND') . "'\n";
echo "   selected_currency = '" . ($_SESSION['selected_currency'] ?? 'NOT FOUND') . "'\n";

echo "\n5. Full Session Array:\n";
foreach ($_SESSION as $key => $value) {
    echo "   \$_SESSION['" . $key . "'] = '" . $value . "'\n";
}
?>
