Skip to content

Wrapper for Maxmind's GeoIP PHP extension.

License

Notifications You must be signed in to change notification settings

onassar/PHP-Geo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP-Geo

The PHP-Geo library contains one static class which acts as a wrapper for the PHP geoip extension/module. It's goal was to provide a more straightforward, naturally understood API for accessing geo-location data about a remote/IP address.

Worth noting is that if you go into the source itself, the scope of methods may throw you off. This is due to how the geoip plugin works.

Specifically, if it can't find an IP address, it throws a notice. This can be tough to deal with in a development environment where errors are set to high, and it simply pollutes your log files. To get around this, I used the magic __callStatic method to act as a wrapper for all methods that ought to be publicly accessible.

This method captures notices and politely discards them, to prevent any wonky flow from entering your application.

City/Country Lookup Example

require_once APP . '/vendors/PHP-Geo/GeoIP.class.php';
echo GeoIP::getCity() . ', ' . GeoIP::getCountry();
exit(0);

While the remote/IP address used for the lookup is determined automagically by the wrapper (including determining if the request is being passed through a load balancer, in which case the HTTP_X_FORWARDED_FOR property is used instead), it can be set for manual lookups.

About

Wrapper for Maxmind's GeoIP PHP extension.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages