<?php
// Get the user's IP address
$client_ip = $_SERVER['REMOTE_ADDR'];

// Fetch allowed IPs from the database
$allowed_ips = [];
$sql_ip = "SELECT ip_address FROM allowed_ips";
$result_ip = $db2->query($sql_ip);

while ($row_ip = $result_ip->fetch_assoc()) {
    $allowed_ips[] = $row_ip['ip_address'];
}

// Restrict access for non-Super Admin users
if ($userrole != 1 && !in_array($client_ip, $allowed_ips)) {
    echo "Access Denied: You are not allowed to access this system from this IP.";
    exit();
}
?>