What is the best practice for initializing sessions in PHP to avoid errors?

When initializing sessions in PHP, it is important to start the session before any output is sent to the browser. This can help avoid errors related to headers already being sent. To ensure proper session initialization, it is recommended to call session_start() at the beginning of your PHP script before any HTML or whitespace.

<?php
// Start the session before any output is sent
session_start();

// Your PHP code here
?>