Location: PHPKode > scripts > Infosniper Geolocation XML API > infosniper-geolocation-xml-api/PHP5/infosniper_IPQuery.php
<?php
//----------------------------------------------
// Infosniper Geolocation Service
// Release Date 2010/03/27
//----------------------------------------------

//----------------------------------------------
function infosniper_IPQuery ( $queryKey , $queryLanguage )
 {
  //----------------------------------------------
  // Determine the users ip address
   $ip_address = $_SERVER [ "REMOTE_ADDR"          ];
  #$ip_address = $_SERVER [ "HTTP_X_FORWARDED_FOR" ];
  #$ip_address = $_SERVER [ "HTTP_CLIENT_IP"       ];
  #$ip_address = getenv   ( "HTTP_X_FORWARDED_FOR" );
  #$ip_address = getenv   ( "HTTP_CLIENT_IP"       );
  #$ip_address = getenv   ( "REMOTE_ADDR"          );
  //----------------------------------------------
  // Query URL
  $queryUrl = "http://www.infosniper.net/xml.php?ip_address=".$ip_address;

  // Create Query with Personal Query Key
  if ( $queryKey != "" ) { $queryUrl = $queryUrl."&k=".$queryKey; }

  // Set Language Parameter
  if ( $queryLanguage == "1" ) { $queryLanguage = "&lang=1"; }
  elseif ( $queryLanguage == "2" ) { $queryLanguage = "&lang=2"; }
  else { $queryLanguage = "&lang=1"; }

  // Create complete Query URL
  $queryUrl = $queryUrl.$queryLanguage;

  // Run Query
  $xmlString = file_get_contents ( $queryUrl );
  $xml = new SimpleXMLElement ( $xmlString );
  //----------------------------------------------
  // Create Result Array
  $results = array ();

  // Fill Result Array
  $results [ "ipaddress"   ] = $xml->result[0]->ipaddress;
  $results [ "hostname"    ] = $xml->result[0]->hostname;
  $results [ "provider"    ] = htmlentities ( $xml->result[0]->provider );
  $results [ "country"     ] = htmlentities ( $xml->result[0]->country  );
  $results [ "countrycode" ] = $xml->result[0]->countrycode;
  $results [ "countryflag" ] = $xml->result[0]->countryflag;
  $results [ "state"       ] = htmlentities ( $xml->result[0]->state    );
  $results [ "city"        ] = htmlentities ( $xml->result[0]->city     );
  $results [ "areacode"    ] = $xml->result[0]->areacode;
  $results [ "postalcode"  ] = $xml->result[0]->postalcode;
  $results [ "dmacode"     ] = $xml->result[0]->dmacode;
  $results [ "timezone"    ] = $xml->result[0]->timezone;
  $results [ "gmtoffset"   ] = $xml->result[0]->gmtoffset;
  $results [ "continent"   ] = $xml->result[0]->continent;
  $results [ "latitude"    ] = $xml->result[0]->latitude;
  $results [ "longitude"   ] = $xml->result[0]->longitude;
  $results [ "queries"     ] = $xml->result[0]->queries;

  // Return XML Results
  return $results;
  //----------------------------------------------
 }
//----------------------------------------------
?>
Return current item: Infosniper Geolocation XML API