What is the correct way to store and pass values as sessions in PHP?

When storing and passing values as sessions in PHP, it is important to start the session using session_start() at the beginning of each script that will be using session variables. To store values in a session, you can simply assign the value to a session variable using the $_SESSION superglobal array. To pass session values between scripts, make sure to start the session in each script and access the session variables using $_SESSION.

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

// Store a value in a session variable
$_SESSION['username'] = 'JohnDoe';

// Access the session variable in another script
session_start();
echo $_SESSION['username'];
?>