What are some common methods to deactivate a website for maintenance in PHP, while allowing admin access?

To deactivate a website for maintenance in PHP while still allowing admin access, you can create a flag in your database or configuration file that indicates whether the site is in maintenance mode. Then, you can check for this flag in your code and redirect all users to a maintenance page except for admins who have a specific access key or role.

// Check if the site is in maintenance mode
if ($maintenance_flag) {
    // Check if the user is an admin
    if ($_SESSION['user_role'] !== 'admin') {
        header("Location: maintenance.php");
        exit();
    }
}