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

When starting a session in PHP scripts, it is important to follow best practices to ensure security and efficiency. It is recommended to start the session as early as possible in your script and to regenerate the session ID periodically to prevent session fixation attacks. When destroying a session, make sure to unset all session variables and destroy the session cookie to ensure that no sensitive information is left behind.

// Starting a session
session_start();
session_regenerate_id();

// Destroying a session
$_SESSION = array();
session_destroy();
setcookie(session_name(), '', time() - 3600, '/');