What potential issues can arise when trying to set SESSION variables on a web server in PHP?

One potential issue when setting SESSION variables in PHP is that the session must be started before any output is sent to the browser. This can lead to "headers already sent" errors if output is sent before starting the session. To solve this, ensure that session_start() is called at the beginning of the script before any output.

<?php
session_start();

// Set session variables
$_SESSION['username'] = 'example_user';
$_SESSION['email'] = 'user@example.com';
?>