How can the $_SESSION['admin'] variable be properly set during user login to control access to different sections of a website?

To properly set the $_SESSION['admin'] variable during user login, you can check the user's credentials against a database and if they are an admin, set $_SESSION['admin'] to true. This variable can then be used to control access to different sections of the website based on the user's role.

// Check user credentials and set $_SESSION['admin'] if user is an admin
if($username == 'admin' && $password == 'password'){
    $_SESSION['admin'] = true;
} else {
    $_SESSION['admin'] = false;
}