PHPackages                             bitolaco/geoipcheck - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bitolaco/geoipcheck

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bitolaco/geoipcheck
===================

v0.1.1(11y ago)115MPLPHPPHP &gt;=5.3.0

Since Jan 19Pushed 10y ago1 watchersCompare

[ Source](https://github.com/BitolaCo/php-geoip-check)[ Packagist](https://packagist.org/packages/bitolaco/geoipcheck)[ RSS](/packages/bitolaco-geoipcheck/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/05b97603290877afab808207de35562a34c99f2c46fddabb90c926ce3bca4b43/68747470733a2f2f706f7365722e707567782e6f72672f6269746f6c61636f2f67656f6970636865636b2f762f737461626c65)](https://packagist.org/packages/bitolaco/geoipcheck)[![Total Downloads](https://camo.githubusercontent.com/861c7c53456c9dc889a5e7f779a1f653d7a0c98f230f634737aef09fbe812019/68747470733a2f2f706f7365722e707567782e6f72672f6269746f6c61636f2f67656f6970636865636b2f646f776e6c6f616473)](https://packagist.org/packages/bitolaco/geoipcheck)[![Latest Unstable Version](https://camo.githubusercontent.com/b4d9e55786fbf520c6058ea807b93dcd97d008ec994aa800940792ee4131f735/68747470733a2f2f706f7365722e707567782e6f72672f6269746f6c61636f2f67656f6970636865636b2f762f756e737461626c65)](https://packagist.org/packages/bitolaco/geoipcheck)[![License](https://camo.githubusercontent.com/4b74b28f2ccd40b324b7ca84a08c1b2053c5aaaa2e4f91bd6740e5f4f8d6405a/68747470733a2f2f706f7365722e707567782e6f72672f6269746f6c61636f2f67656f6970636865636b2f6c6963656e7365)](https://packagist.org/packages/bitolaco/geoipcheck)

This is simple function which prints different strings depending on the location of the HTTP request.

It makes use of the MaxMind GeoIP API for PHP. See [https://github.com/maxmind/geoip-api-php](github.com/maxmind/geoip-api-php)for more details about the API.

Requirements
------------

[](#requirements)

You must have Composer installed and/or downloaded. Visit [getcomposer.org](http://getcomposer.org) for more info.

You must also install the GeoIP City database, since we can't package it with the code due to license restrictions. Your Linux distro will likely have packages for the PHP geo-ip extension. If you're using Ubuntu, it's as simple as:

```
sudo apt-get install php5-geoip

```

Have instructions for another system? Create a pull request and we'll merge it.

PHP 5.3 or newer is also required, primarily due to the reliance on anonymous functions.

Installation
------------

[](#installation)

The MaxMind API was installed here via Composer, and is included in this package. If you're already using composer, change the require line in example.php to match the location of your Composer autoload file.

Make sure it's a requirement in your composer.json file.

```
{
  "require": {
    "bitolaco/geoipcheck": "~0.1"
  }
}

```

Make sure your php includes the file:

```
require_once '/path/to/composer/autoload.php';

```

Usage
-----

[](#usage)

Usage is very simple.

```
$geoIp = new GeoIpCheck();

```

If your using a MaxMind database which is not in one of the following locations, you'll need to enter the path to the database when initializing the object. The script automatically looks for the file in these locations:

```
/usr/local/share/GeoIP/GeoIP.dat
/usr/local/share/GeoIP/GeoLiteCity.dat
/usr/local/share/GeoIP/GeoIPCity.dat
/usr/share/GeoIP/GeoIP.dat
/usr/share/GeoIP/GeoLiteCity.dat
/usr/share/GeoIP/GeoIPCity.dat

```

If you're using a custom location, simply specify it like this:

```
$geoIp = new GeoIpCheck('/path/to/geoip/database.dat');

```

If you want to override the IP address (i.e. not use the IP of the request, simple change the first line to:

```
$geoIp = new GeoIpCheck();
$geoIp->overrideRequestIp('');

```

Then, to run a check, specify both the search type and the value to match.

```
$geoIp->check(
    'Name of city/cities/regions/etc.',
    'Type of search',
    function() { /* Callback to execute if the check is true.  */ },
    function() { /* Callback to execute if the check is false. */ }
);

```

Valid search types include:

```
country_code, country_code3, city, latitude, longitude, area_code, metro_code, region, postal_code, dma_code, continent_code

```

Valid search values, the first argument, can be a string, a comma separated string, or an array. All these would be valid.

```
$type = 'Boston';
$type = 'Boston,Cambridge';
$type = array('Boston', 'Cambridge');

```

The whole example, if you wanted to check if the current visitor was from Boston or Cambridge:

```
$geoIp = new GeoIpCheck();
$geoIp->check(
    'Boston,Cambridge',
    'city',
    function() { echo "You are not from Boston or Cambridge"; },
    function() { echo "You are from Boston or Cambridge"; }
);

```

If the details of the last request are stored in the `GeoIpCheck::$lastResult` variable. So anywhere in your script, you could access data such as:

```
$geoIp->lastRequest->city;
$geoIp->lastRequest->country_code;
$geoIp->lastRequest->area_code;
// And so forth...

```

Full Example
------------

[](#full-example)

You can see an example in the `example/index.php` file. It doesn't have any external requirements other than the code in this repository, so you can run it using the built-in PHP web-server.

To Do
-----

[](#to-do)

- Add basic unit testing.
- Cache results in memory (memcached, apc, etc.), if available.
- Cache entire database in memory, if available.

Suggestions
-----------

[](#suggestions)

This was built for a client, and you're seeing the vanilla version here.

Have any suggestions for features? Bugs? Comments? Create an issue in the issue tracker.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4135d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62cbca5b98a5b62486589f8984b6b551e2841c166d780483a049801bace58e6a?d=identicon)[bradberger](/maintainers/bradberger)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bitolaco-geoipcheck/health.svg)

```
[![Health](https://phpackages.com/badges/bitolaco-geoipcheck/health.svg)](https://phpackages.com/packages/bitolaco-geoipcheck)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
