PHP 之ip查询接口

/**
 * @param $ip 待查询的ip
 * @return mixed
 */
function getIpAddressInfo($ip)
{
    $ipurl = 'http://api.ip138.com/query/?ip=' . $ip . '&datatype=txt';
    $ipheader = array('token:注册的token');
    $ipch = curl_init();
    curl_setopt($ipch, CURLOPT_URL, $ipurl);
    curl_setopt($ipch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ipch, CURLOPT_HTTPHEADER, $ipheader);
    curl_setopt($ipch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ipch, CURLOPT_CONNECTTIMEOUT, 3);
    $iphandles = curl_exec($ipch);
    curl_close($ipch);
    return $iphandles;
}

 

posted @ 2019-04-23 10:31  样子2018  阅读(695)  评论(0编辑  收藏  举报