How can PHP sessions be used to store user data across multiple pages?
PHP sessions can be used to store user data across multiple pages by starting a session with session_start() at the beginning of each page where you want to access the stored data. You can then set session variables using $_SESSION['key'] = 'value' and retrieve them on subsequent pages. This allows you to maintain user-specific data throughout their session on your website.
// Start the session
session_start();
// Store user data in session variables
$_SESSION['username'] = 'JohnDoe';
$_SESSION['email'] = 'johndoe@example.com';
// Retrieve user data on another page
session_start();
echo 'Username: ' . $_SESSION['username'];
echo 'Email: ' . $_SESSION['email'];