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

Common pitfalls when using session_start() in PHP include calling session_start() after output has already been sent to the browser, not checking if the session is already started before calling session_start(), and not setting session.save_path properly. To avoid these pitfalls, make sure to call session_start() at the beginning of your script, check if the session is already started using session_status(), and set session.save_path in your php.ini file.

<?php
// Check if session is already started before calling session_start()
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}