php xml get_ip_geo_info

Discussions regarding API development - so not necessarily the core codebase or database - but things to connect to it, either remotely or in conjunction to the database

Moderator: Moderators

php xml get_ip_geo_info

Postby sorcerer2 on Sun Feb 11, 2007 6:28 pm

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;
}
sorcerer2
n00b
 
Posts: 6
Joined: Sun Feb 11, 2007 6:24 pm
Location: Melbourne, FL

Postby Shven on Fri Mar 02, 2007 4:24 am

tnx!
Shven
n00b
 
Posts: 2
Joined: Fri Mar 02, 2007 4:21 am


Return to API development

Who is online

Users browsing this forum: No registered users and 1 guest

cron