What are common pitfalls when using PHP sessions, especially in pre-configured environments like xAMP?

Common pitfalls when using PHP sessions in pre-configured environments like xAMP include not properly setting the session save path, not starting the session before accessing or setting session variables, and not properly destroying the session when it is no longer needed. To solve these issues, make sure to set the session save path to a writable directory, start the session at the beginning of your script, and destroy the session when it is no longer needed.

<?php
// Set the session save path to a writable directory
session_save_path('/path/to/writable/directory');

// Start the session
session_start();

// Access or set session variables
$_SESSION['username'] = 'john_doe';

// Destroy the session when it is no longer needed
session_destroy();
?>