How can PHP sessions be effectively managed to differentiate between an administrator and a regular user during login?

To differentiate between an administrator and a regular user during login, you can set a session variable upon successful login that stores the user's role. This session variable can then be checked on subsequent pages to determine the user's role and provide appropriate access levels.

// Upon successful login, set a session variable to store the user's role
$_SESSION['user_role'] = 'administrator'; // or 'regular_user'

// On subsequent pages, check the session variable to determine the user's role
if ($_SESSION['user_role'] === 'administrator') {
    // Administrator-specific actions
} else {
    // Regular user actions
}