How can a PHP developer ensure that only the admin has access to a website during maintenance, while restricting access for other users?

To ensure that only the admin has access to a website during maintenance, while restricting access for other users, the PHP developer can check the user's role or permission level before allowing access to the website. This can be done by setting a session variable when the admin logs in and checking that variable during maintenance. If the user is not an admin, they can be redirected to a maintenance page or shown a message indicating restricted access.

session_start();

if($_SESSION['role'] !== 'admin'){
    header("Location: maintenance_page.php");
    exit();
}