What best practices should be followed when handling sessions in PHP to prevent errors like "Trying to destroy uninitialized session"?

When handling sessions in PHP, it is important to check if a session is active before trying to destroy it to prevent errors like "Trying to destroy uninitialized session". This can be done by checking if the session is set before calling session_destroy(). Additionally, it is good practice to start the session before attempting to destroy it.

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

// Check if session is active before destroying it
if (isset($_SESSION)) {
    session_destroy();
}
?>