I have a snippet of code from an existing system that is pulling the users 2-digit country code from an obsolete database table. Normally I have updated the table on a regular basis but I am quite honestly sick of doing it. What I would like to do is make this more of a live pull each time a user logs in. This is the existing code
public static function geoip_country_code_by_name($ip)
{
if ($_SERVER['HTTP_CF_IPCOUNTRY']) {
return $_SERVER['HTTP_CF_IPCOUNTRY'];
}
$sql = "SELECT country FROM ip2country WHERE ip < INET_ATON('$ip') ORDER BY ip DESC LIMIT 0,1";
$res = DB::selectOneBySQL($sql);
return $res->country;
}
I am looking for suggestions on how to best accomplish this.