Code Monkey home page Code Monkey logo

sandfox_geoip's Introduction

Overview

This extension allows you to use free GeoIP Lite database by MaxMind with your Magento installation.

Installation

Just copy all files to your Magento installation respecting directory structure. Make sure your var directory is writable by web-server user (by default it should be). If you want GeoIP database to be updated automatically make sure your Magento cron-job is set up and running. Logging out and in is not required.

Configuration

After installation a new field will be added to System\Configuration\General\General\Countries Options group indicating the date of last database update and the button to force synchronization. Note that frequent synchronizations will result you being banned at MaxMind server for several hours. MaxMind GeoIP Lite database is updated on first Thursday of the month so if you have have Magento cron-job running you will not need to force synchronization anymore but on the first run.

Usage

This extension only adds MaxMind GeoIP Lite database to your Magento installation and maintains its updates. It doesn't do anything else out of the box (yet). However if comes with a set of methods you can implement in your template or extension.

$geoIP = Mage::getSingleton('geoip/country');

/**
 * Returns you the ISO 3166-1 code of visitors country.
 */
echo $geoIP->getCountry();

/**
 * Returns true or false depending if current visitors country is among allowed countries.
 * If there are no allowed countries in the system returns true.
 */
if ($geoIP->isCountryAllowed()) {
    // ...
}

/**
 * Adds country (or array of countries) to list of allowed countries.
 */
$geoIP->addAllowedCountry('DE');
$geoIP->addAllowedCountry(array(
    'US',
    'CA'
));

/**
 * Or just get a country code of a specific IP
 */
echo $geoIP->getCountryByIp('94.230.212.77');

Please note that geoip/country is initialized at each Magento load. In order to save system resources please always use it as a singleton.

The list of allowed countries is initially populated from System\Configuration\General\General\Countries Options\Alowed Countries multi-select field of your Magento configuration. The addAllowedCountry method is not adding country to system configuration but adds it to internal list extension uses for isCountryAllowed method.

Global Restrict

To globally restrict access to your site by IP consider extending the controller_front_init_before event in your own module and add dependancy to geoip

Credits

Thanks a lot to MaxMind for providing a free database. Additionally this extension partly uses the code from MaxMind GeoIP PHP API.

sandfox_geoip's People

Contributors

tim-bezhashvyly avatar convenient avatar schrank avatar nickw108 avatar peterjaap avatar robholmes avatar sergeifilippov avatar alanpuccinelli avatar hgati avatar seansan avatar

Watchers

James Cloos avatar  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.