What are common pitfalls when using the session_start() function in PHP and how can they be avoided?

One common pitfall when using the session_start() function in PHP is calling it after any output has been sent to the browser, as it will result in a "headers already sent" error. To avoid this, ensure that session_start() is called at the beginning of the script before any HTML or whitespace.

<?php
// Correct way to start a session
session_start();

// Rest of your PHP code goes here
?>