Skip to content

lbcd/CravlerMaxMindGeoIpBundle

 
 

Repository files navigation

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'
        connection_type: 'GeoIP2-Connection-Type.mmdb'
        anonymous_ip: 'GeoIP2-Anonymous-IP.mmdb'
        domain: 'GeoIP2-Domain.mmdb'
        isp: 'GeoIP2-ISP.mmdb'
    source:
        country: 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz'
        city: 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz'
        connection_type: ~
        anonymous_ip: ~
        domain: ~
        isp: ~

If you have bought a licence, fill your user_id and licence_key and fill source URL in config.yml. Example :

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'
        city: null

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

YOU MUST USE --no-md5-check WHEN YOU CHANGE SOURCE URL

Download and update the MaxMind GeoIp2 database

php app/console cravler:maxmind:geoip-update

You can use the --no-md5-check option if you want to skip MD5 check.

php app/console cravler:maxmind:geoip-update --no-md5-check

How to use

$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'

License

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

LICENSE

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%