Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/labor-digital/max-mind-helpers
Helper package to implement IP to geolocation resolving based on the MaxMind database
https://github.com/labor-digital/max-mind-helpers
Last synced: about 1 month ago
JSON representation
Helper package to implement IP to geolocation resolving based on the MaxMind database
- Host: GitHub
- URL: https://github.com/labor-digital/max-mind-helpers
- Owner: labor-digital
- License: apache-2.0
- Created: 2020-04-28T20:11:47.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-04-28T20:23:53.000Z (over 4 years ago)
- Last Synced: 2024-04-21T02:41:28.119Z (9 months ago)
- Language: PHP
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Max Mind Helpers
This library utilizes the free [Max Mind GeoLite2 Database](https://dev.maxmind.com/geoip/geoip2/geolite2/#IP_Geolocation_Usage) to perform IP => geolocation queries. The package downloads the MaxMind library to your local filesystem, so you can be sure that the client's IP will never leave your server.The package consists of two parts. The first one is the "Downloader" which simplifies the process of "getting" the database and the "Reader" that is a wrapper around Maxmind's implementation. The reader can also cache queries to save performance using a PSR-16 SimpleCache\CacheInterface
## Installation
Install this package using Composer:```
composer require labor-digital/max-mind-helpers
```## Usage
Download the database:
```php
doDownloadIfRequired();// Optional
// Always triggers a download ignoring all requirements.
$forceDownload = true;
if($forceDownload) $downloader->download();// Get path to library file
$libraryFile = $downloader->getLibraryFile();
```Use the database:
```php
getLocation('129.200.121.12');
// Result ['latitude' => 0.0, 'longitude' => 0.0];
// Result if query failed: NULL// Get the geolocation of the current client's ip
$location = $reader->getLocation();
// Result's as above. If you use this at 127.0.0.1 the result will always be NULL// Get additional information of an ip
$info = $reader->getInformation('129.200.121.12');
```## Further reading
* https://github.com/maxmind/MaxMind-DB-Reader-php
* https://dev.maxmind.com/geoip/geoip2/geolite2/#IP_Geolocation_Usage## Postcardware
You're free to use this package, but if it makes it to your production environment, we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.Our address is: LABOR.digital - Fischtorplatz 21 - 55116 Mainz, Germany.
We publish all received postcards on our [company website](https://labor.digital).