How can session variables be properly declared in PHP?

Session variables in PHP can be properly declared by starting the session with session_start() at the beginning of your script, and then setting session variables using the $_SESSION superglobal array. It is important to make sure that session_start() is called before trying to access or set any session variables.

<?php
// Start the session
session_start();

// Set a session variable
$_SESSION['username'] = 'JohnDoe';
?>