如何在php中使用ip地址获取移动国家代码

问题描述 投票:0回答:1

我必须得到基于IP的移动国家代码,即印度=> 91,英格兰=> 41等我使用下面的代码,但它不起作用。

码,

$ip = $_SERVER['REMOTE_ADDR'];
$data = file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip);
$data = json_decode($data);
php ip
1个回答
0
投票

它给出了以下回应

$ip = $_SERVER['REMOTE_ADDR'];
$data = file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip);
$data = json_decode($data);
print_($data);

Repsone

{
  ["geoplugin_request"]=>
  string(13) "XX.XX.XX.XXX"
  ["geoplugin_status"]=>
  int(200)
  ["geoplugin_credit"]=>
  string(143) "Some of the returned data includes GeoLite data created by MaxMind, available from <a href='http://www.maxmind.com'>http://www.maxmind.com</a>."
  ["geoplugin_city"]=>
  string(9) "New Delhi"
  ["geoplugin_region"]=>
  string(5) "Delhi"
  ["geoplugin_areaCode"]=>
  string(1) "0"
  ["geoplugin_dmaCode"]=>
  string(1) "0"
  ["geoplugin_countryCode"]=>
  string(2) "IN"
  ["geoplugin_countryName"]=>
  string(5) "India"
  ["geoplugin_continentCode"]=>
  string(2) "AS"
  ["geoplugin_latitude"]=>
  string(4) "28.6"
  ["geoplugin_longitude"]=>
  string(4) "77.2"
  ["geoplugin_regionCode"]=>
  string(2) "07"
  ["geoplugin_regionName"]=>
  string(5) "Delhi"
  ["geoplugin_currencyCode"]=>
  string(3) "INR"
  ["geoplugin_currencySymbol"]=>
  string(7) "&#8360;"
  ["geoplugin_currencySymbol_UTF8"]=>
  string(3) "₨"
  ["geoplugin_currencyConverter"]=>
  float(64.1725)
}

从上面你会得到国家geoplugin_countryCode这是iso代码,

一旦你有iso国家代码,你可以很容易地获得国家国家拨号代码。 (保留拨号国家代码和iso代码映射的数组)示例

$ country = array('IN'=> 91,......);

我希望这会有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.