1

I have seen a couple different ways to check if a PHP variable is an ipv4 or v6. But I have not found a way that checks for the different types of IPV6. So if the V6 IP is not entered in one certain format it will not be flagged as an IPV6.

I need something to check for IPV4 VS IPV6 while also checking the different types of IPV6

6
  • 1
    try read this -> stackoverflow.com/questions/1448871/… Commented Dec 10, 2014 at 16:44
  • There's no builtin IPv6 class/prefix check in PHP. You'll have to write one. It's not clear why your question is about mixing it with IPv4/v6 differentiation. Commented Dec 10, 2014 at 16:47
  • After @mario comment. It may be easy to check if a var is an ipv4. Otherwise you can think that is an ipv6 Commented Dec 10, 2014 at 16:48
  • To clear up my question I need a function to check a variable if it is an IP of V4 or V6. But it needs to check the multiple types of formats of v6 so no matter what format the user puts it in it is caught. Commented Dec 10, 2014 at 17:01
  • @pschemm031 can you edit your question and add some possible types a user can input Commented Dec 10, 2014 at 17:28

1 Answer 1

0
if ($ipv4=filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { echo "$ipv4 is ipv4"; } elseif ($ipv6=filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { echo "$ipv6 is ipv6"; } else { echo "Invaid IPv4/6: $ip"; } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.