What is the recommended method for managing sessions in PHP, and why is session_register() no longer recommended?

The recommended method for managing sessions in PHP is to use the $_SESSION superglobal array to store and retrieve session variables. The session_register() function is no longer recommended as it has been deprecated since PHP 5.3.0 and removed in PHP 5.4.0 due to security concerns and potential vulnerabilities.

<?php
// Start the session
session_start();

// Set a session variable
$_SESSION['username'] = 'JohnDoe';

// Retrieve the session variable
$username = $_SESSION['username'];

// Destroy the session
session_destroy();
?>