Git Product home page Git Product logo

geoip2country's Introduction

PHP GeoIP2Country PRO (v2.0.6)

Donate Build Status Scrutinizer Code Quality Code Intelligence Status GitHub license

An IP address is only the beginning of endless possibilities, adventures and developments...

What's GeoIP2Country PRO?

A PHP IP Address Geolocation library to help you identify visitors geographical location. This component is Build with an eye to keeping it as lightweight and lookups as fast as possible. And there are no external requests being made during runtime. So, if you need to get your website visitor's country and you don't want to use any API then this is the best solution for you. The project include methods to quickly update your GEOIP DATABASE with the least possible human intervention (for donors only).

What's new in this release?

  • Complete refactoring and optimization of processing algorithms
  • A new database engine (combining security and efficiency)
  • A new component dedicated to updating the database?
  • A repository based on statistical data from ICANN (Internet Corporation for Assigned Names and Numbers)

NOTE:

In order to encourage people to support this project, database update components are not included in this repository as they are for donors only. Thus any donor will receive a full copy of this software, including the component that will help him to make his GEOIP database stay up to date. However, other users can still use the software as published here. Only the database update functionality will not be available

Donate here: Donate

Requirements

  • pdo_sqlite (runtime deps)
  • php_curl (for update only)

Installation And Initialisation :

These instructions will get you a copy of the project up and running on your local machine. there are two options:

  • import(copy) GeoIP2Country files into a specific folder of your project
  • Using Composer installer(Recommended) by typing the following command:
composer require atchondjo/geoip2country

Usage: (using Composer autoloader)

require __DIR__ . '/vendor/autoload.php';

try
{
    $IP2Country = new iriven\GeoIP2Country();

} catch (\Throwable $th) {
    trigger_error($th->getMessage(), E_USER_ERROR);
}

Getting Country code from given IP address:

    $ipAddress_1='2a00:1450:4007:816::2004';
    $ipAddress_2='37.140.250.97';
    $ipAddress_3='2001:41d0:301::21';
    $ipAddress_4='216.58.201.228';
    $ipAddress_5='188.165.53.185';
    $ipAddress_6='10.10.201.12';

    echo '<pre>';
    echo $IP2Country->resolve($ipAddress_1).PHP_EOL;
    echo $IP2Country->resolve($ipAddress_2).PHP_EOL;
    echo $IP2Country->resolve($ipAddress_3).PHP_EOL;
    echo $IP2Country->resolve($ipAddress_4).PHP_EOL;
    echo $IP2Country->resolve($ipAddress_5).PHP_EOL;
    echo $IP2Country->resolve($ipAddress_6).PHP_EOL;

Getting current visitor Country code (auto detect his IP address):

    echo '<pre>';
    echo $IP2Country->resolve().PHP_EOL;  /** resolve() method called without any argument */

Retrieving Country name:

Because one of my publications already deals with the recovery of a country's name from its ISO code. I chose in this project to limit myself to the only search of the country's ALPHA2 ISO code from a given ip address. So, to retrieve the country name (and much more), you must instantiate the "WorldCountriesDatas" class available from HERE, and pass the result of the previous command as follows:

$CountryName ='n/a';
$CountryCode = $IP2Country->resolve($ipAddress);
if(!$IP2Country->isReservedAddress($ipAddress))
{
  require_once 'WorldCountriesDatas.php';
  $DataProvider = new \Iriven\WorldCountriesDatas();
  $CountryName = $DataProvider->getCountryName($CountryCode);
}

Updating GeoIP datas: (for Donors only)

require __DIR__ . '/vendor/autoload.php';

try
{
    $IP2CountryBackend = new iriven\GeoIP2CountryServer();
    $IP2CountryBackend->updateDatabase();

} catch (\Throwable $th) {
    trigger_error($th->getMessage(), E_USER_ERROR);
}

/*
* NOTE: In order to encourage people to support this project, database update components are not included in this
* repository as they are for donors only. Thus any donor will receive a full copy of this software,
* including the component that will help him to make his GEOIP database stay up to date.
*/

Compatibility:

  • IPV4
  • IPV6

Authors

License

This project is licensed under the GNU General Public License V3 - see the LICENSE file for details

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Donate

Acknowledgments

  • This project uses GeoIp data by ICANN, available from Here

Disclaimer

If you use this library in your project please add a backlink to this page by this code.

<a href="https://github.com/iriven/GeoIP2Country" target="_blank">This Project Uses Alfred's TCHONDJO GeoIP2Country PRO.</a>

geoip2country's People

Contributors

iriven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

geoip2country's Issues

Problems initializing

I've copied the script to my server and tried to run it a first time, pulling my local IP's country.
However, no IP data was downloaded, only the subdirectory "GeoIPDatas" created. I've changed directory rights to "777", script now returned "IP Ranges provider file not found in /var/www/vhosts/mydomain.com/httpdocs/inc/GeoIPCountry.php on line 282

I've copied the subdirectory included in the package to the subdirectory - then the function gave a result, but incorrect country returned. Might have to do with outdated state - so I called $IP2Country->Admin()->updateDatabase(); in the code, but it didn't seem to do anything?

bug in update

when i update db its stuck in 127.php and the all ips save in it
the file get bigger to 4,5 mb
and any file after 127.php ignore it and no updated?
untitled

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.