What are the best practices for handling user sessions in PHP, considering the deprecation of session_register()?

The best practice for handling user sessions in PHP, considering the deprecation of session_register(), is to use the $_SESSION superglobal array to set and retrieve session variables. This ensures that the session data is securely stored on the server and can be accessed throughout the user's session.

// Start the session
session_start();

// Set session variables
$_SESSION['username'] = 'example_user';
$_SESSION['email'] = 'user@example.com';

// Retrieve session variables
$username = $_SESSION['username'];
$email = $_SESSION['email'];

// Unset session variables
unset($_SESSION['username']);
unset($_SESSION['email']);

// Destroy the session
session_destroy();