note 109919 modified in function.filter-var by danbrown

From: 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&#39;s very likely that you actually want to detect all reserved ranges, not just private IPs, and there&#39;s another constant for them that should be bitwise-OR&#39;d with it.&#13;&#10;&#60;?php&#13;&#10;function is_private_ip($ip) {&#13;&#10; return !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);&#13;&#10;}&#13;&#10;?&#62; --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

« previous php.notes (#190489) next »