How can sessions be utilized to transfer data between PHP pages in a secure manner?

Sessions can be utilized to transfer data between PHP pages in a secure manner by storing the data in the $_SESSION superglobal array. This array is accessible across different pages as long as the session is active. To ensure security, it is important to properly sanitize and validate the data before storing it in the session.

// Start the session
session_start();

// Store data in the session
$_SESSION['username'] = 'exampleuser';

// Retrieve data from the session on another page
session_start();
$username = $_SESSION['username'];