What is the purpose of using session variables in PHP and how are they typically utilized in web development?

Session variables in PHP are used to store information that needs to be accessed across multiple pages during a user's visit to a website. They are typically utilized to keep track of user data, such as login information, shopping cart contents, or user preferences. Session variables are stored on the server and are unique to each user's session, making them a secure way to maintain user-specific data.

// Start the session
session_start();

// Set a session variable
$_SESSION['username'] = 'JohnDoe';

// Access the session variable on another page
session_start();
echo $_SESSION['username'];