I have a web application which takes the IP. I want to know if we can use a function to detect the type of IP in PHP (IPv4 or IPv6)?
I know we can get the IP in PHP by using this:
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
This gives the IP address but I can't find the variable which gives what type of IP it got (IPv4, IPv6).
Any help or leads?