-
- function address_baidu($ip) {
- $u = "";
- $address = file_get_contents(" http://open.baidu.com/ipsearch/s?wd={$ip}&tn=baiduip");
- preg_match('#来自:(.+)#Ui', $address, $m);
- return strval($m[1]);
- }
- function GetRemoteIp($default='127.0.0.1')
- {
- $ip_string = $_SERVER['HTTP_CLIENT_IP'].','.$_SERVER['HTTP_X_FORWARDED_FOR'].','.$_SERVER['REMOTE_ADDR'];
- if ( preg_match ("/d+.d+.d+.d+/", $ip_string, $matches) )
- {
- return $matches[0];
- }
- return $default;
- }
- $ip = GetRemoteIp();
- $addr = address_baidu($ip);
复制代码
还有其他方法:
腾讯新浪通过IP地址获取当前地理位置(省份)的接口
腾讯的接口是 ,返回数组 http://fw.qq.com/ipaddress
返回值 var IPData = new Array("61.135.152.194","","北京市","");
新浪的接口 : http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js
多地域测试方法:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=218.192.3.42
可以简单使用:
>>>
|