I use the Maxmind geoip database for retrieving a users country. We store all login attempts in mysql and often people login with different ip’s. This is not an issue if the ip’s are from the same country but if the password is shared on the boards you’ll see all sort of countries using it.
I now use this for retrieving the country and ip:
$ipaddress = (long2ip($row['ip']));
$country_name = geoip_country_name_by_addr($gi, "$ipaddress");
$country_iso = geoip_country_code_by_addr($gi, "$ipaddress");
and then count the number of distinct ip addresses:
$count_ip = "SELECT distinct ip FROM members WHERE username='".$row['username']."'";
$result_ip = mysql_query($count_ip);
$ips = mysql_num_rows($result_ip);
if thats more then 1 i get a message.
But I would like to compare the Country codes for all ip addresses used by a username so i can see if the username is used by different countries and then give a message.
How would i do that? I have the array of ip’s and i need to first check the ip’s for country code and then see if it differs.
Your query already returns all IP addresses, so you have to go through the result rows:
Btw, I’m assuming you add a date range to your query; otherwise you would negatively impact those who travel 😉