http://www.php.net/manual/en/filter.filters.flags.php
In order to filter on loopback addresses try this :
<?php
function FILTER_FLAG_NO_LOOPBACK_RANGE($value) {
// Fails validation for the following loopback IPv4 range: 127.0.0.0/8
// This flag does not apply to IPv6 addresses
return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? $value :
(((ip2long($value) & 0xff000000) == 0x7f000000) ? FALSE : $value);
}
$var = filter_var('127.0.0.1', FILTER_CALLBACK, array('options' => 'FILTER_FLAG_NO_LOOPBACK_RANGE'));
// Returns FALSE
$var = filter_var('74.125.19.103', FILTER_CALLBACK, array('options' => 'FILTER_FLAG_NO_LOOPBACK_RANGE'));
// Returns '74.125.19.103'
// To filter Private IP ranges and Loopback ranges
$var = filter_var('127.0.0.1', FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)
&& filter_var('127.0.0.1', FILTER_CALLBACK, array('options' => 'FILTER_FLAG_NO_LOOPBACK_RANGE'));
// Returns FALSE
?>
(If someone wants to write in handling for the IPv6 loopback interface at “::1” go for it.)