我希望通过IP地址获取国家/地区代码,州代码,城市名称
答案 0 :(得分:0)
您可以使用https://www.ip2location.com等第三方服务,它将为您提供所需的所有详细信息。您必须调用此类服务的rest api,该服务将向您返回数据
答案 1 :(得分:0)
You can use this API to get information like country_code,country_name, region_code,region_name, city,zipcode,latitude, longitude,metro_code,areacode
$location = file_get_contents('http://freegeoip.net/json/'.$_SERVER['REMOTE_ADDR']);
print_r($location);
{ "ip": "77.99.179.98",
"country_code": "GB",
"country_name": "United Kingdom",
"region_code": "H9",
"region_name": "London, City of",
"city": "London",
"zipcode": "",
"latitude": 51.5142,
"longitude": -0.0931,
"metro_code": "",
"areacode": "" }