What best practices should be followed when starting and managing sessions in PHP scripts?

When starting and managing sessions in PHP scripts, it is important to follow best practices to ensure security and efficiency. This includes starting the session at the beginning of the script, setting session variables securely, and destroying the session when it is no longer needed.

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

// Set session variables
$_SESSION['username'] = 'example_user';
$_SESSION['is_logged_in'] = true;

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