<?php
function _httpCurl($url, $type='get', $res='json', $jsonp='', $arr='', $headers=[]){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
}
if ($type == 'post') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
}
$cnt = curl_exec($ch);
if (curl_errno($ch)) {
return;
}
curl_close($ch);
if ($res == 'json') {
return json_decode($cnt, true);
}
return $cnt;
}
$ip = $_SERVER["REMOTE_ADDR"];;//在使用的时候只需要把这个IP换成你想要查的IP就可以了
$url = 'https://open.onebox.so.com/dataApi?type=ip&src=onebox&query=ip&ip='.$ip.'&url=ip';
$res = _httpCurl($url);
echo $res[1];
?>
PHP获取IP归属地
最新推荐文章于 2024-08-16 11:34:02 发布