-
- function address_baidu($ip) {
- $u = "";
- $address = file_get_contents(" http://open.baidu.com/ipsearch/s?wd={$ip }&tn=baiduip");
- preg_match('#From: (.+)#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);
Copy code
There are other methods:
Tencent Sina's interface to obtain the current geographical location (province) through IP address
Tencent’s interface is and returns an array http://fw.qq.com/ipaddress
Return value var IPData = new Array("61.135.152.194","","Beijing City","");
Sina interface: http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js
Multi-region testing method: http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=218.192.3.42
Easy to use:
>>>
|