note 109919 modified in function.filter-var by danbrown
| From: | danbrown@php.net | Date: | Tue, 04 Sep 2012 14:28:38 +0000 |
| Subject: | note 109919 modified in function.filter-var by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190489@lists.php.net to get a copy of this message | ||
It's very likely that you actually want to detect all reserved ranges, not just private IPs,
and there's another constant for them that should be bitwise-OR'd with
it. <?php function is_private_ip($ip) {
return !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE |
FILTER_FLAG_NO_RES_RANGE); } ?>
--was--
Further to joelhy's tip about checking private IPs, it's very likely that you actually
want to detect all reserved ranges, not just private IPs, and there's another constant for them
that should be bitwise-OR'd with it.
<?php
function is_private_ip($ip) {
return !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE |
FILTER_FLAG_NO_RES_RANGE);
}
?>
http://php.net/manual/en/function.filter-var.php