What are the best practices for handling session side-effects in PHP scripts, especially in relation to global variables and register_globals setting?

Session side-effects in PHP scripts can be handled by avoiding the use of global variables and disabling the `register_globals` setting. Instead, use `$_SESSION` superglobal array to store session data securely. This ensures that session data is isolated and not affected by other variables in the script.

<?php
// Start session
session_start();

// Store session data in $_SESSION superglobal
$_SESSION['username'] = 'JohnDoe';

// Retrieve session data
$username = $_SESSION['username'];

// Destroy session
session_destroy();
?>