How can session handling be properly implemented in PHP?

Session handling in PHP can be properly implemented by starting the session at the beginning of each script, setting session variables as needed, and destroying the session when it is no longer needed. This ensures that session data is securely stored and managed throughout the user's interaction with the website.

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

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

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