Giter VIP home page Giter VIP logo

maxmind-geoip's Introduction

Maxmind GeoIp Library

Symfony bundle to easily use maxmind geoip bundle.

SensioLabsInsight Build

Installation

To install this library please follow the next steps:

First add the dependencie to your composer.json file:

"require": {
    ...
    "maxmind/geoip": "dev-master"
},

Then install the bundle with the command:

php composer update

Enable the bundle in your application kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Maxmind\Bundle\GeoipBundle\MaxmindGeoipBundle(),
    );
}

Now the library is installed.

To get the maxmind data source file (in '.dat' format), you can choose between one of the two following purposed methods:

You can go on the maxmind free download data page: http://dev.maxmind.com/geoip/geolite And get the needed version. Then you have to unzip the downloaded file in the data directory located in 'vendor/maxmind/geoip/data'.

Or you can simply execute this command:

php app/console maxmind:geoip:update-data %url-data-source%

Replace %url-data-source% with the url of the needed data source. ex: http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

If you want to use your data file in another directory, you can configure it on app\config\config.yml

# app/config/config.yml
maxmind_geoip:
	data_file_path: "%kernel.root_dir%/../web/GeoIPCity.dat"

Now can use the Maxmind GeoIp Library everywhere in your Symfony2 application.

Usage

The following examples are available if you are in a controller

$geoip = $this->get('maxmind.geoip')->lookup(%IP_ADDR%);

$geoip->getCountryCode();
$geoip->getCountryCode3();
$geoip->getCountryName();
$geoip->getRegion();
$geoip->getCity();
$geoip->getPostalCode();
$geoip->getLatitude();
$geoip->getLongitude();
$geoip->getAreaCode();
$geoip->getMetroCode();
$geoip->getContinentCode();

Or in twig file

{{ ip|geoip.countryCode }}
{{ ip|geoip.countryCode3 }}
{{ ip|geoip.countryName }}
{{ ip|geoip.regionCode }}
{{ ip|geoip.region }}
{{ ip|geoip.city }}
{{ ip|geoip.postalCode }}
{{ ip|geoip.latitude }}
{{ ip|geoip.longitude }}
{{ ip|geoip.areaCode }}
{{ ip|geoip.metroCode }}
{{ ip|geoip.continentCode }}

You can add a demo route in your 'routing_dev' to get an example on how this bundle work for example:

_maxmind_geoip:
    resource: "@MaxmindGeoipBundle/Controller/DemoController.php"
    type:     annotation
    prefix:   /demo

Get a lookup at /demo/geoip

This library is an import of Maxmind GeoIp Free Library, you can find at http://www.maxmind.com/

maxmind-geoip's People

Contributors

konandrum avatar emilio-staropoli avatar tgabi333 avatar masterro94 avatar whyte624 avatar aferrandini avatar oktapodia avatar burahimu avatar ghua avatar p5-atcaci avatar kbazsi avatar marcoshoya avatar frak avatar jenyak avatar skilla avatar tezd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.