0) { $subnetBytes = substr($subnet, 0, $maskBytes); $ipBytes = substr($ip, 0, $maskBytes); if ($subnetBytes !== $ipBytes) { return false; } } if ($maskBits > 0) { $maskValue = (1 << $maskBits) - 1; $maskValue <<= (8 - $maskBits); $subnetByte = ord($subnet[$maskBytes]); $ipByte = ord($ip[$maskBytes]); if (($subnetByte & $maskValue) !== ($ipByte & $maskValue)) { return false; } } return true; } return $ip === $network; } }