PHP学院的中学生 2021-01-07 17:56:56 1680次浏览 2条回复 1 0 0
<?php

function ipToArea($ip=""){
    $api="http://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=".$ip."&co=&resource_id=6006";
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$api);
    curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
    //curl_setopt($ch,CURLOPT_HTTPHEADER,C('IP138_TOKEN'));
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,3);
    $handles = curl_exec($ch);
    curl_close($ch);
    $handles= iconv('GB2312', 'UTF-8', $handles);
    $arr=json_decode($handles,true);
	print_r($arr);die;
    return $arr['data'][0]['location'];
}
 
//使用范例
$address= ipToArea("183.253.44.75"); //8.8.8.8是google公司免费提供的dns
echo $address;
您需要登录后才可以回复。登录 | 立即注册