IP位址獲取當前地理位置(省份)的介面

2021-09-07 03:18:16 字數 1153 閱讀 3248

返回值 var ipdata = new array("61.135.152.194","","北京市","");

多地域測試方法:

返回值 var remote_ip_info = ;

使用騰迅的api介面,php獲取ip位址以及所在城市

返回類似:var ipdata = new array("61.51.71.183","","北京市","");

** 

public

static

function positionaction($ip) ");

//curl_setopt($ch,curlopt_encoding ,'utf8');

curl_setopt($ch, curlopt_timeout, 10

); curl_setopt($ch, curlopt_returntransfer,

true); //

獲取資料返回

$location =json_decode(curl_exec($ch));

curl_close($ch);

if ($location->ret == -1

)

return

[

'status

' => 1

,

'info

' => '

獲取地理位置成功',

'handle

' =>$location

];}

/*

** 通過**ip介面獲取ip地理位置

* @param string $ip

* @return: string**/

function getcity($ip)  

$city = $ipinfo->data->region.$ipinfo->data->city;

return

$city; }

header("content-type:text/html;charset=utf-8");

//這樣呼叫,顯示山東省臨沂市

var_dump(getcity("112.234.69.189"));

?>

通過IP位址獲取當前地理位置(省份)的介面

html view plain copy 通過 ip位址庫獲取ip位置 1.請求介面 get 位址字串 2.響應資訊 json格式的 國家 省 自治區或直轄市 市 縣 運營商 3.返回資料格式json 其中code的值的含義為,0 成功,1 失敗。function gettaobaoaddress ...

php獲取ip位址所在的地理位置

function getiplocation queryip ip getiplocation 111.186.116.208 將ip傳入進來 print r ip 列印結果 如果把提交的 result列印出來的話,顯示如下 最後顯示的結果為中國上海市 教育 2,通過 提供的介面 header co...

通過IP位址獲取地理位置資訊

本方法通過 的乙個開源服務實現的,如下 通過ip位址獲取地理位置資訊 ip server remote addr echo ip ip url ip json decode file get contents url echo var dump ip echo if string ip code 1...