What are common pitfalls when handling sessions in PHP, especially for beginners?

Common pitfalls when handling sessions in PHP, especially for beginners, include not starting the session before using any session variables, forgetting to properly destroy the session when it's no longer needed, and not properly securing the session data to prevent session hijacking.

<?php
// Start the session at the beginning of your script
session_start();

// Store session data
$_SESSION['username'] = 'john_doe';

// Destroy the session when it's no longer needed
session_destroy();

// Secure the session data by setting session cookie parameters
session_set_cookie_params([
    'lifetime' => 3600,
    'path' => '/',
    'domain' => 'example.com',
    'secure' => true,
    'httponly' => true
]);
?>