For a little project of mine i want to print the city (the name) on the screen with the ip of the user, i already have something to get his/her IP but i dont how to get the city where he/she is from....
the code i use right now to get the ip+:
function getUserIP()
{
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
if(filter_var($client, FILTER_VALIDATE_IP))
{
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP))
{
$ip = $forward;
}
else
{
$ip = $remote;
}
return $ip;
}
$user_ip = getUserIP();
echo $user_ip; // Output IP address [Ex: 177.87.193.134]
credits: How to get a user's IP address in PHP?
does anyone have an idea how i should get it to work? You dont have to write something for me, but a hint or a link to a othore tread would really help! Tips are always welcome!