Thinkphp IP获取和对应的城市

  Thinkphp系统内置了get_client_ip方法用于获取客户端的IP地址, 在common函数里面,下面如何获取ip地址及对应的城市的

1,获取ip地址

   $ip = get_client_ip();

2,如何对应的城市

  使用淘宝的开放接口
  接口地址
  淘宝的开放接口URL格式为:

  http://ip.taobao.com/service/getIpInfo.php?ip=117.136.42.86

   $ret = https_request($url);
   $arr = json_decode($ret,true);

  或者curl方法

文章来自 www.huthon.com

猜你喜欢

转载自blog.csdn.net/gzxiaomei/article/details/82852239