Class: Net_GeoIP
Source Location: /Net_GeoIP-1.0.0/Net/GeoIP.php
GeoIP class provides an API for performing geo-location lookups based on IP address.
Author(s):
|
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
[line 136]
GeoIP class provides an API for performing geo-location lookups based on IP address. To use this class you must have a [binary version] GeoIP database. There is a free GeoIP country database which can be obtained from Maxmind: http://www.maxmind.com/app/geoip_country SIMPLE USE Create an instance:
Depending on which database you are using (free, or one of paid versions) you must use appropriate lookup method: // for free country db:
// for [non-free] region db:
list ($ctry_code, $region) = $geoip->lookupRegion($_SERVER['REMOTE_ADDR']);
// for [non-free] city db:
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']);
MULTIPLE INSTANCES You can have several instances of this class, one for each database file you are using. You should use the static getInstance() singleton method to save on overhead of setting up database segments. Note that only one instance is stored per filename, and any flags will be ignored if an instance already exists for the specifiedfilename. Special note on using SHARED_MEMORY flag If you are using SHARED_MEMORY (shmop) you can only use SHARED_MEMORY for one (1) instance (i.e. for one database). Any subsequent attempts to instantiate using SHARED_MEMORY will read the same shared memory block already initialized, and therefore will cause problems since the expected database format won't match the database in the shared memory block. Note that there is no easy way to flag "nice errors" to prevent attempts to create new instances using SHARED_MEMORY flag and it is also not posible (in a safe way) to allow new instances to overwrite the shared memory block. In short, is you are using multiple databses, use the SHARED_MEMORY flag with care. LOOKUPS ON HOSTNAMES Note that this PHP API does NOT support lookups on hostnames. This is so that the public API can be kept simple and so that the lookup functions don't need to try name lookups if IP lookup fails (which would be the only way to keep the API simple and support name-based lookups). If you do not know the IP address, you can convert an name to IP very simply using PHP native functions or other libraries:
Or, if you don't know whether an address is a name or ip address, use application-level logic: if (ip2long($ip_or_name) === false ) {
} else {
$ip = $ip_or_name;
}
Class Variables
Method Detail
Documentation generated on Mon, 11 Mar 2019 15:43:44 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|
|