Skip to content

Instantly share code, notes, and snippets.

@markbrody
markbrody / cidr_whitelist.php
Last active February 23, 2018 22:16
php whitelist that supports cidr notation
<?php
function is_whitelisted($remote_ip) {
$whitelisted = false;
$remote_ip = sprintf("%u", ip2long($remote_ip));
$records = ["127.0.0.0/10", "10.0.0.1", "192.168.1.0/24"];
foreach ($records as $record) {
$ip = $record;
$cidr = 32;
if (strpos($record, "/"))