Jump to content

IP4 and IP6 Filter


AndyXS

Recommended Posts

Here we have two IP filters, without having to do a double if statement, if there an easy way to say.. If valid IP4 or IP6?

 

$ip = '192.168.37';
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE) // displays IP is not valid
{
echo 'IP is not valid.';
} else {
echo 'IP is valid.';
}

$ip = '2001:0cb8:25a3:04c1:1324:8a2b:0471:8221';
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE) // displays IP is valid
{
echo 'IP is not valid.';
} else {
echo 'IP is valid.';
}

Link to comment
https://forums.phpfreaks.com/topic/180048-ip4-and-ip6-filter/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.