<?php function query_ipinfo_ipinfodb($ip) { $ch=curl_init("http://api.ipinfodb.com/v3/ip-city/?key=a9fc56a2f741b511195b4429ba0f3e3b1b9644ca45ac24f61bd70d0980039576&ip=$ip"); curl_setopt($ch,CURLOPT_HEADER,false); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_TIMEOUT,2); $response=curl_exec($ch); curl_close($ch); $parts=explode(';',$response); if ($parts[0]!='OK') return array(); $data=array( 'Ip'=>$parts[2], 'CountryCode'=>$parts[3], 'Region'=>strtoupper($parts[5]) ); if ($parts[10]) { list($hour,$minutes)=explode(':',$parts[10]); $data['Gmtoffset']=($hour<0?(-$hour*60-$minutes):($hour*60+$minutes))*60; } else $data['Gmtoffset']=round($parts[9]/15.0)*3600; return $data; } function query_ipinfo_geoio($ip) { $ch=curl_init("http://api.geoio.com/q.php?key=eZeacbRd6yKWatlx&qt=geoip&d=tab&q=$ip"); curl_setopt($ch,CURLOPT_HEADER,false); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_TIMEOUT,2); $response=curl_exec($ch); curl_close($ch); $parts=explode('\t',$response); $data=array( 'Ip'=>$ip, 'CountryCode'=>$parts[6], 'Region'=>strtoupper($parts[1]), 'Gmtoffset'=>round($parts[5]/15.0)*3600 ); return $data; } function query_ipinfo_utrace($ip) { $ch=curl_init("http://xml.utrace.de/?query=$ip"); curl_setopt($ch,CURLOPT_HEADER,false); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_TIMEOUT,2); $response=curl_exec($ch); curl_close($ch); if (!$response) return array(); $xml=simplexml_load_string($response); $data=array( 'Ip'=>(string)$xml->result[0]->ip, 'CountryCode'=>(string)$xml->result[0]->countrycode, 'Region'=>strtoupper((string)$xml->result[0]->region), 'Gmtoffset'=>round($xml->result[0]->longitude/15.0)*3600 ); return $data; } function query_ipinfo($ip) { for ($time=0;$time<3;$time++) { $ipdata=query_ipinfo_ipinfodb($ip); if ($ipdata) break; $ipdata=query_ipinfo_geoio($ip); if ($ipdata) break; $ipdata=query_ipinfo_utrace($ip); if ($ipdata) break; } return $ipdata; } ?>