How can you store and retrieve user information in sessions in PHP?
To store and retrieve user information in sessions in PHP, you can use the $_SESSION superglobal array. You can store user information by assigning values to specific keys in the $_SESSION array, and retrieve this information by accessing the same keys. Make sure to start the session using session_start() at the beginning of your PHP script.
<?php
// Start the session
session_start();
// Store user information in session
$_SESSION['username'] = 'JohnDoe';
$_SESSION['email'] = 'johndoe@example.com';
// Retrieve user information from session
$username = $_SESSION['username'];
$email = $_SESSION['email'];
// Output user information
echo "Username: " . $username . "<br>";
echo "Email: " . $email;
?>