新浪通过IP地址获取当前地理位置(ip端、国家、省份、城市、运营商)的php接口很强大呢/**<br>
* 取得地理位置信息<br>
* $format : js json string<br>
* return $array<br>
*/<br>
function iplookup($format='json'){<br>
//返回Sina地理位置信息<br>
$res = restRequest('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format='.$format);<br>
$res = json_decode($res,true);<br>
return $res;<br>
}
/**<br>
* 调用REST服务<br>
*/<br>
function restRequest($url, $method = 'GET', $data, $contentType = 'application/json', $timeout = 30, $proxy = false) {<br>
$ch = null;<br>
if ('POST' === strtoupper($method)) {<br>
$ch = curl_init($url);<br>
curl_setopt($ch, CURLOPT_POST, 1);<br>
curl_setopt($ch, CURLOPT_HEADER,0 );<br>
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br>
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);<br>
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);<br>
if($contentType) {<br>
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:'.$contentType));<br>
}<br>
if(is_string($data)){<br>
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);<br>
} else {<br>
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));<br>
}<br>
} elseif('GET' === strtoupper($method)) {<br>
if(is_string($data)) {<br>
$real_url = $url. (strpos($url, '?') === false ? '?' : ''). $data;<br>
} else {<br>
$real_url = $url. (strpos($url, '?') === false ? '?' : ''). http_build_query($data);<br>
}<br>
$ch = curl_init($real_url);<br>
curl_setopt($ch, CURLOPT_HEADER, 0);<br>
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:'.$contentType));<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br>
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);<br>
} else {<br>
$args = func_get_args();<br>
//Log::error($args);<br>
return false;<br>
}<br>
if ($proxy) {<br>
curl_setopt($ch, CURLOPT_PROXY, $proxy);<br>
}<br>
$ret = curl_exec($ch);<br>
$info = curl_getinfo($ch);<br>
$contents = array(<br>
'httpInfo' => array(<br>
'send' => $data,<br>
'url' => $url,<br>
'ret' => $ret,<br>
'http' => $info,<br>
)<br>
);<br>
curl_close($ch);<br>
return $ret;<br>
}
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools