Location: PHPKode > scripts > Infosniper Geolocation XML API > infosniper-geolocation-xml-api/PHP4/infosniper_IPQuery.php
<?php
//----------------------------------------------
// Infosniper Geolocation Service
// PHP4 Version based on 
// 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
  // ---JK--- PHP5 begin
  //$xmlString = file_get_contents ( $queryUrl );
  //$xml = new SimpleXMLElement ( $xmlString );
  // ---JK--- PHP5 end
  // ---JK--- PHP4 begin
  // include SimpleXML for PHP4 class
  require_once "simplexml.class.php";
  $xmlstring = $queryUrl;
  $sxml = new simplexml;
  $xml = $sxml->xml_load_file($xmlstring);
  // -- JK--- PHP4 end
  //----------------------------------------------
  // Create Result Array
  $results = array ();

  // Fill Result Array
  // ---JK--- PHP5 begin
  //$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;
  // ---JK--- PHP5 end
  // ---JK--- PHP4 begin 
  $results [ "ipaddress"   ] = $xml[ipaddress];
  $results [ "hostname"    ] = $xml[hostname];
  $results [ "provider"    ] = htmlentities ( $xml[provider] );
  $results [ "country"     ] = htmlentities ( $xml[country]  );
  $results [ "countrycode" ] = $xml[countrycode];
  $results [ "countryflag" ] = $xml[countryflag];
  $results [ "state"       ] = htmlentities ( $xml[state]    );
  $results [ "city"        ] = htmlentities ( $xml[city]     );
  $results [ "areacode"    ] = $xml[areacode];
  $results [ "postalcode"  ] = $xml[postalcode];
  $results [ "dmacode"     ] = $xml[dmacode];
  $results [ "timezone"    ] = $xml[timezone];
  $results [ "gmtoffset"   ] = $xml[gmtoffset];
  $results [ "continent"   ] = $xml[continent];
  $results [ "latitude"    ] = $xml[latitude];
  $results [ "longitude"   ] = $xml[longitude];
  $results [ "queries"     ] = $xml[queries];
  // ---JK--- PHP4 end
  
  // Return XML Results
  return $results;
  //----------------------------------------------
 }
//----------------------------------------------
?>
Return current item: Infosniper Geolocation XML API