What potential pitfalls should be considered when using session_destroy() in PHP for logging out?

When using session_destroy() in PHP for logging out, one potential pitfall to consider is that it will destroy all session data, not just the current user's session. To avoid this, you can unset specific session variables related to the current user before calling session_destroy(). This way, only the relevant session data is removed.

// Unset specific session variables related to the current user
unset($_SESSION['user_id']);
unset($_SESSION['username']);

// Destroy the session
session_destroy();