How can PHP sessions be utilized to store and retrieve data across multiple pages in a web application?

PHP sessions can be utilized to store and retrieve data across multiple pages in a web application by starting a session using session_start() at the beginning of each page where you want to access session data. You can then store data in the $_SESSION superglobal array using key-value pairs, and retrieve the data on subsequent pages by accessing the array with the appropriate key.

// Start the session
session_start();

// Store data in the session
$_SESSION['username'] = 'JohnDoe';
$_SESSION['email'] = 'johndoe@example.com';

// Retrieve data from the session
$username = $_SESSION['username'];
$email = $_SESSION['email'];

// Output the retrieved data
echo "Username: $username <br>";
echo "Email: $email";