I'm trying to get my user's IPv4 address when they connect to my site but it gives me the IPv6 address instead:
2a01:cb04:8ed3:b300:d3d:71c1:a883:5b61
And I want an IPv4 address that looks like this:
255.255.255.1
here is my code :
function get_client_ip()
{
$ipaddress = '';
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else if (isset($_SERVER['HTTP_X_FORWARDED'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
} else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
} else if (isset($_SERVER['HTTP_FORWARDED'])) {
$ipaddress = $_SERVER['HTTP_FORWARDED'];
} else if (isset($_SERVER['REMOTE_ADDR'])) {
$ipaddress = $_SERVER['REMOTE_ADDR'];
} else {
$ipaddress = 'UNKNOWN';
}
return $ipaddress;
}
i've tried many approach but it keeps giving me weird ip adress. It was functionning on local but it is not on my server.