php ip validation filter_var with IPv4-translated Address like ::ffff:0:a.b.c.d

$ip = "::ffff:0:10.0.0.3";
if (!filter_var($ip, FILTER_VALIDATE_IP) === false) {
  echo("$ip is a valid IP address");
} else {
  echo("$ip is not a valid IP address");
}

this return invalid although it is a valid ip

thanks in advance

728x90

1 Answers php ip validation filter_var with IPv4-translated Address like ::ffff:0:a.b.c.d

Try inet_pton as answered here: PHP function to validate IPv4 and IPv6 using regex

function validateIP($ip){
    return inet_pton($ip) !== false;
}

That answer also suggests a whole load of methods. If none of them work then either that is not a valid IP or PHP as a bug that you should report.

3 year ago