What potential issues can arise when handling sessions in PHP?

One potential issue when handling sessions in PHP is session fixation, where an attacker sets the session ID for a user before they authenticate, allowing them to hijack the session. To prevent this, regenerate the session ID after a user authenticates.

session_start();

if (!isset($_SESSION['authenticated'])) {
    // Perform authentication process

    // Regenerate session ID
    session_regenerate_id();
    
    $_SESSION['authenticated'] = true;
}