Why you are using JS for this? What if user JS is off? I would use PHP instead
Create a table for maintenance with a column say maintenance_status
, now this will hold a boolean value, 0 1... 0 => off, 1 => on, will keep only a single record which will be created once, and later will update it always...
So now later you create this function
function check_maintenance($connection) { /* Call this function on every page,
pass your database connection var
as a function parameter */
$query = mysqli_fetch_array(mysqli_query($connection, "SELECT * FROM tbl_maintenance LIMIT 1"));
/* Limit 1 is optional if you are using only 1 row as I told you,
if you are keeping records of the previous maintenance, probably
you've to sort desc and use limit 1 */
if($query['tbl_maintenance'] == '1') { //Check boolean value, if it's on than redirect
header('Location: maintenance.php'); //Redirect the user to maintenance page
exit;
}
}