freegeoip不再起作用了

几个月前,我创建了一个代码,用于检测访客国家并显示合法的饮酒年龄。 欧盟国家为18,其他国家为21。

我正在使用freegeoip。

代码工作得很好,但现在我注意到它不再起作用了。

$.get("http://freegeoip.net/json/", function (response) { $("#ip").html("IP: " + response.ip); $("#country_code").html(response.country_code); if(response.country_code=='AL','AD','AT','BY','BE','BA','BG','HR','CY','CZ','DK','EE','FO','FI','FR','DE','GI','GR','HU','IS','IE','IT','LV','LI','LT','LU','MK','MT','MD','MC','NL','NO','PL','PT','RO','RU','SM','RS','SK','SI','ES','SE','CH','UA','VA','RS','IM','RS','ME') { $(".age").html("18"); } else { $(".age").html("21"); } }, "jsonp"); 

在这里我告诉年龄:

 ARE YOU OVER ? 

我认为问题出在freegeoip中,但我无法修复它。

您也可以像freegeoip一样使用ip-api.com:

 function getDataOfIp($ip) { try { $pageContent = file_get_contents('http://ip-api.com/json/' . $ip); $parsedJson = json_decode($pageContent); return [ "country_name" => $parsedJson->country, "country_code" => $parsedJson->countryCode, "time_zone" => $parsedJson->timezone ]; } catch (Exception $e) { return null; } } 

我刚刚找到了问题的答案。 我注意到freegeoip.net网站不起作用所以我改变了服务。

我用http://getcitydetails.geobytes.com/GetCityDetails?callback=?替换了http://freegeoip.net/json/ http://getcitydetails.geobytes.com/GetCityDetails?callback=?

并添加了

现在代码再次运行。

Interesting Posts