freegeoip doesn't work anymore

…衆ロ難τιáo~ 提交于 2019-12-07 20:36:30

You can also use ip-api.com like freegeoip :

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;
    }
}

I just found an answer for the problem. I noticed that the freegeoip.net website doesn't work so I changed the service.

I replaced the http://freegeoip.net/json/ with http://getcitydetails.geobytes.com/GetCityDetails?callback=?

and added <script language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesLocationCode,GeobytesCode,GeobytesInternet,GeobytesFqcn"></script>

Now the code works again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!