Page 1 of 1

php xml get_ip_geo_info

PostPosted: Sun Feb 11, 2007 6:28 pm
by sorcerer2
Enjoy

define("IP", 0);
define("CITYSTATE", 1);
define("COUNTRY", 2);
define("CC", 3);
define("LATLON", 4);

function get_ip_geo_info($ip) {
include_once 'clsParseXML.php'; //From http://www.phpfreaks.com/files/clsParseXML.zip
$url = "http://api.hostip.info/get_xml.php?ip=$ip&position";
$xmlparse = &new ParseXML;
$xml = $xmlparse->GetXMLTree($url);
$result[IP] = $ip;
if (isset($xml['HOSTIPLOOKUPRESULTSET'][0]['GML:FEATUREMEMBER'][0]['HOSTIP'][0]['GML:NAME'][0]['VALUE'])) $result[CITYSTATE] = $xml['HOSTIPLOOKUPRESULTSET'][0]['GML:FEATUREMEMBER'][0]['HOSTIP'][0]['GML:NAME'][0]['VALUE'];
if (isset($xml['HOSTIPLOOKUPRESULTSET'][0]['GML:FEATUREMEMBER'][0]['HOSTIP'][0]['COUNTRYNAME'][0]['VALUE'])) $result[COUNTRY] = $xml['HOSTIPLOOKUPRESULTSET'][0]['GML:FEATUREMEMBER'][0]['HOSTIP'][0]['COUNTRYNAME'][0]['VALUE'];
if (isset($xml['HOSTIPLOOKUPRESULTSET'][0]['GML:FEATUREMEMBER'][0]['HOSTIP'][0]['COUNTRYABBREV'][0]['VALUE'])) $result[CC] = $xml['HOSTIPLOOKUPRESULTSET'][0]['GML:FEATUREMEMBER'][0]['HOSTIP'][0]['COUNTRYABBREV'][0]['VALUE'];
if (isset($xml['HOSTIPLOOKUPRESULTSET'][0]['GML:FEATUREMEMBER'][0]['HOSTIP'][0]['IPLOCATION'][0]['GML:POINTPROPERTY'][0]['GML:POINT'][0]['GML:COORDINATES'][0]['VALUE'])) {
$result[LATLON] = explode(",", $xml['HOSTIPLOOKUPRESULTSET'][0]['GML:FEATUREMEMBER'][0]['HOSTIP'][0]['IPLOCATION'][0]['GML:POINTPROPERTY'][0]['GML:POINT'][0]['GML:COORDINATES'][0]['VALUE']);
}
return $result;
}

PostPosted: Fri Mar 02, 2007 4:24 am
by Shven
tnx!