* $geoip = Net_GeoIP::getInstance('/path/to/geoipdb.dat', Net_GeoIP::SHARED_MEMORY); *
* // for free country db: * $country_name = $geoip->lookupCountryName($_SERVER['REMOTE_ADDR']); * $country_code = $geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']); * * // for [non-free] region db: * list($ctry_code, $region) = $geoip->lookupRegion($_SERVER['REMOTE_ADDR']); * * // for [non-free] city db: * $location = $geoip->lookupLocation($_SERVER['REMOTE_ADDR']); * print "city: " . $location->city . ", " . $location->region; * print "lat: " . $location->latitude . ", long: " . $location->longitude; * * // for organization or ISP db: * $org_or_isp_name = $geoip->lookupOrg($_SERVER['REMOTE_ADDR']); *
* $geoip->lookupCountryName(gethostbyname('www.sunset.se')); *
* if (ip2long($ip_or_name) === false) { * $ip = gethostbyname($ip_or_name); * } else { * $ip = $ip_or_name; * } * $ctry = $geoip->lookupCountryName($ip); *
* // create new instance with memory_cache enabled * $geoip = Net_GeoIP::getInstance('C:\mydb.dat', Net_GeoIP::MEMORY_CACHE); * .... * * // later in code, request instance with no flags specified. * $geoip = Net_GeoIP::getInstance('C:\mydb.dat'); * * // Normally this means no MEMORY_CACHE but since an instance * // with memory cache enabled has already been created for 'C:\mydb.dat', the * // existing instance (with memory cache) will be returned. *