Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.