What is the role of session_start() in PHP session management and how should it be used effectively?

The session_start() function in PHP is used to start a new session or resume an existing session. It should be called at the beginning of every PHP page where session variables are used. This function initializes session data and allows you to store and retrieve session variables across multiple pages.

<?php
// Start the session
session_start();

// Set session variables
$_SESSION['username'] = 'JohnDoe';
$_SESSION['email'] = 'johndoe@example.com';

// Retrieve session variables
echo 'Username: ' . $_SESSION['username'];
echo 'Email: ' . $_SESSION['email'];
?>