What is the difference between IPv4 and IPv6 addresses in PHP?

IPv4 addresses are 32-bit numerical addresses, while IPv6 addresses are 128-bit hexadecimal addresses. In PHP, you can check if an IP address is IPv4 or IPv6 by using the filter_var() function with the FILTER_VALIDATE_IP flag. This function will return true if the IP address is valid and false if it is not.

$ip = "192.168.1.1";

if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    echo "IPv4 address";
} elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
    echo "IPv6 address";
} else {
    echo "Invalid IP address";
}