Download the PHP package bitolaco/geoipcheck without Composer

On this page you can find all versions of the php package bitolaco/geoipcheck. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package geoipcheck

Latest Stable Version Total Downloads Latest Unstable Version License

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 for more details about the API.

Requirements

You must have Composer installed and/or downloaded. Visit 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

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 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('<any valid ipv4 address>');

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

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

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.


All versions of geoipcheck with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
ext-geoip Version ~1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bitolaco/geoipcheck contains the following files

Loading the files please wait ....