php中怎么获取指定IP所有信息,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
具体如下:
<?php
function getIpInfo($ip,$timeout=15) {
if(!function_exists('curl_init') or !function_exists('simplexml_load_string')) return false;
$ch = curl_init("http://ipinfodb.com/ip_query2.php?ip={$ip}&timezone=true");
$options = array(
CURLOPT_RETURNTRANSFER => true,
);
curl_setopt_array($ch,$options);
$res = curl_exec($ch);
curl_close($ch);
if($xml = simplexml_load_string($res)) {
$return = array();
foreach ($xml->Location->children() as $key=>$item) {
$return[$key] = strtolower($item);
}
return $return;
} else {
return false;
}
}
$current_Ip_Info = getIpInfo('119.7.8.255');
var_dump($current_Ip_Info);
关于php中怎么获取指定IP所有信息问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注天达云行业资讯频道了解更多相关知识。