Developed with love by KnpLabs Hire us for your project!
34

CravlerMaxMindGeoIpBundle

by cravler

CravlerMaxMindGeoIpBundle

Installation

Step 1: update your vendors by running

$ php composer.phar require cravler/maxmind-geoip-bundle:dev-master

Step2: Enable the bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...

        new Cravler\MaxMindGeoIpBundle\CravlerMaxMindGeoIpBundle(),
    );
}

Configuration

The default configuration for the bundle looks like this:

cravler_max_mind_geo_ip:
    client:
        user_id: ~
        license_key: ~
        options: {}
    path: '%kernel.root_dir%/Resources/MaxMind'
    db:
        country: 'GeoIP2-Country.mmdb'
        city: 'GeoIP2-City.mmdb'
        asn: 'GeoIP2-ASN.mmdb'
        connection_type: 'GeoIP2-Connection-Type.mmdb'
        anonymous_ip: 'GeoIP2-Anonymous-IP.mmdb'
        enterprise: 'GeoIP2-Enterprise'
        domain: 'GeoIP2-Domain.mmdb'
        isp: 'GeoIP2-ISP.mmdb'
    source:
        country: 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz'
        city: 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz'
        asn: 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz'
        connection_type: ~
        anonymous_ip: ~
        enterprise: ~
        domain: ~
        isp: ~
    md5_check:
        country: 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz.md5'
        city: 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz.md5'
        asn: 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz.md5'
        connection_type: ~
        anonymous_ip: ~
        enterprise: ~
        domain: ~
        isp: ~

If you have bought a licence.

cravler_max_mind_geo_ip:
    client:
        user_id: 123456
        license_key: abcd1234
        ...
    source:
        country: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoIP2-Country&suffix=tar.gz&license_key=abcd1234'
        ...
    md5_check:
        country: ~
        ...

NB! Do not forget to change your licence key in URL source. You can find links in MaxMind website in your setting manualy update.

Download and update the MaxMind GeoIp2 database

php bin/console cravler:maxmind:geoip-update

You can use the --no-md5-check option if you want to skip MD5 check.
bash
php bin/console cravler:maxmind:geoip-update --no-md5-check

On Symfony 2.8 or older use app/console instead of bin/console

How to use

Database Reader

$geoIpService = $container->get('cravler_max_mind_geo_ip.service.geo_ip_service');

// Replace "city" with the appropriate method for your database, e.g., "country".
$record = $geoIpService->getRecord('128.101.101.101', 'city');

print($record->country->isoCode . "\n"); // 'US'
print($record->country->name . "\n"); // 'United States'
print($record->city->name . "\n"); // 'Minneapolis'

Web Service Client

$geoIpService = $container->get('cravler_max_mind_geo_ip.service.geo_ip_service');

$client = $geoIpService->getClient();

$record = $client->city('128.101.101.101');

License

This bundle is under the MIT license. See the complete license in the bundle:

LICENSE
The MIT License (MIT)

Copyright (c) 2014 Sergei Vizel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

cravler_max_mind_geo_ip:
client:
user_id: ~
license_key: ~
options: []
path: %kernel.root_dir%/Resources/MaxMind
db:
country: GeoIP2-Country.mmdb
city: GeoIP2-City.mmdb
asn: GeoIP2-ASN.mmdb
connection_type: GeoIP2-Connection-Type.mmdb
domain: GeoIP2-Domain.mmdb
isp: GeoIP2-ISP.mmdb
anonymous_ip: GeoIP2-Anonymous-IP.mmdb
enterprise: GeoIP2-Enterprise.mmdb
source:
country: https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz
city: https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
asn: https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz
connection_type: ~
domain: ~
isp: ~
anonymous_ip: ~
enterprise: ~
md5_check:
country: https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz.md5
city: https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz.md5
asn: https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz.md5
connection_type: ~
domain: ~
isp: ~
anonymous_ip: ~
enterprise: ~
  • command service ID fix
    By cravler, 2 months ago
  • Merge pull request #21 from antondavidsen/deprecate-container-aware-command
    By web-flow, 2 months ago
  • Deprecate ContainerAwareCommand and inject configuration
    By Anton Davidsen, 5 months ago
  • UpdateDatabaseCommand improvements
    By cravler, 11 months ago
  • small improvements
    By cravler, 11 months ago
  • Merge pull request #19 from henri9813/create_exceptions
    By web-flow, 11 months ago
  • Create exception for the service
    By , 11 months ago
  • Merge pull request #16 from henri9813/add_asn_database
    By web-flow, 1 year ago
  • Update Readme
    By henri9813, 1 year ago
  • Add ASN database
    By henri9813, 1 year ago
  • Merge pull request #13 from Ne-Lexa/master
    By web-flow, 1 year ago
  • Fix deprecation for symfony/config 4.2
    By , 1 year ago
  • Merge pull request #11 from bpolaszek/patch-1
    By web-flow, 1 year ago
  • Enable autowiring
    By web-flow, 1 year ago
  • README.md
    By cravler, 1 year ago
  • cleaning
    By cravler, 1 year ago
  • Composer script handler fix
    By cravler, 1 year ago
  • SF 2.7+ support
    By cravler, 1 year ago
  • explicit commands registration
    By web-flow, 1 year ago
  • Merge pull request #10 from bpolaszek/master
    By web-flow, 2 years ago
  • Allow SF 4.0+
    By bpolaszek, 2 years ago
  • Make service explicitely public (SF 3.3+)
    By bpolaszek, 2 years ago
  • Removed Container dependency
    By bpolaszek, 2 years ago
  • Merge pull request #8 from 22h/master
    By web-flow, 2 years ago
  • change console command example in readme for use in symfony 3 or higher and add a fallback for older versions
    By Magnus ReiƟ, 2 years ago
  • Merge pull request #7 from foaly-nr1/patch-https
    By web-flow, 3 years ago
  • Make the internet a more secure place
    By foaly-nr1, 3 years ago
  • Improve update database
    By cravler, 3 years ago
  • branch-alias 1.x-dev
    By cravler, 4 years ago
  • Merge pull request #2 from bpolaszek/master
    By cravler, 4 years ago