How can PHP sessions be used to store and retrieve user information for personalized profiles?

To store and retrieve user information for personalized profiles using PHP sessions, you can set session variables with the user's information upon login and then retrieve and display this information on the profile page.

// Start the session
session_start();

// Set session variables upon user login
$_SESSION['user_id'] = 123;
$_SESSION['username'] = 'john_doe';
$_SESSION['email'] = 'john.doe@example.com';

// Retrieve and display user information on the profile page
echo 'User ID: ' . $_SESSION['user_id'] . '<br>';
echo 'Username: ' . $_SESSION['username'] . '<br>';
echo 'Email: ' . $_SESSION['email'];