Download the PHP package geoip2/geoip2 without Composer

On this page you can find all versions of the php package geoip2/geoip2. 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 geoip2

GeoIP2 PHP API

Description

This package provides an API for the GeoIP2 and GeoLite2 web services and databases.

Install via Composer

We recommend installing this package with Composer.

Download Composer

To download Composer, run in the root directory of your project:

You should now have the file composer.phar in your project directory.

Install Dependencies

Run in your project root:

You should now have the files composer.json and composer.lock as well as the directory vendor in your project directory. If you use a version control system, composer.json should be added to it.

Require Autoloader

After installing the dependencies, you need to require the Composer autoloader from your code:

Install via Phar

Although we strongly recommend using Composer, we also provide a phar archive containing most of the dependencies for GeoIP2. Our latest phar archive is available on our releases page.

Install Dependencies

In order to use the phar archive, you must have the PHP Phar extension installed and enabled.

If you will be making web service requests, you must have the PHP cURL extension installed to use this archive. For Debian based distributions, this can typically be found in the the php-curl package. For other operating systems, please consult the relevant documentation. After installing the extension you may need to restart your web server.

If you are missing this extension, you will see errors like the following:

Require Package

To use the archive, just require it from your script:

Optional C Extension

The MaxMind DB API includes an optional C extension that you may install to dramatically increase the performance of lookups in GeoIP2 or GeoLite2 databases. To install, please follow the instructions included with that API.

The extension has no effect on web-service lookups.

IP Geolocation Usage

IP geolocation is inherently imprecise. Locations are often near the center of the population. Any location provided by a GeoIP2 database or web service should not be used to identify a particular address or household.

Database Reader

Usage

To use this API, you must create a new \GeoIp2\Database\Reader object with the path to the database file as the first argument to the constructor. You may then call the method corresponding to the database you are using.

If the lookup succeeds, the method call will return a model class for the record in the database. This model in turn contains multiple container classes for the different parts of the data such as the city in which the IP address is located.

If the record is not found, a \GeoIp2\Exception\AddressNotFoundException is thrown. If the database is invalid or corrupt, a \MaxMind\Db\InvalidDatabaseException will be thrown.

See the API documentation for more details.

City Example

Anonymous IP Example

Connection-Type Example

Domain Example

Enterprise Example

ISP Example

Database Updates

You can keep your databases up to date with our GeoIP Update program. Learn more about GeoIP Update on our developer portal.

There is also a third-party tool for updating databases using PHP and Composer. MaxMind does not offer support for this tool or maintain it. Learn more about the Geoip2 Update tool for PHP and Composer on its GitHub page.

Web Service Client

Usage

To use this API, you must create a new \GeoIp2\WebService\Client object with your $accountId and $licenseKey:

You may also call the constructor with additional arguments. The third argument specifies the language preferences when using the ->name method on the model classes that this client creates. The fourth argument is additional options such as host and timeout.

For instance, to call the GeoLite2 web service instead of the GeoIP2 web service:

To call the Sandbox GeoIP2 web service instead of the production GeoIP2 web service:

After creating the client, you may now call the method corresponding to a specific endpoint with the IP address to look up, e.g.:

If the request succeeds, the method call will return a model class for the endpoint you called. This model in turn contains multiple record classes, each of which represents part of the data returned by the web service.

If there is an error, a structured exception is thrown.

See the API documentation for more details.

Example

Values to use for Database or Array Keys

We strongly discourage you from using a value from any names property as a key in a database or array.

These names may change between releases. Instead we recommend using one of the following:

What data is returned?

While many of the end points return the same basic records, the attributes which can be populated vary between end points. In addition, while an end point may offer a particular piece of data, MaxMind does not always have every piece of data for any given IP address.

Because of these factors, it is possible for any end point to return a record where some or all of the attributes are unpopulated.

See the GeoIP2 web service docs for details on what data each end point may return.

The only piece of data which is always returned is the ipAddress attribute in the GeoIp2\Record\Traits record.

Integration with GeoNames

GeoNames offers web services and downloadable databases with data on geographical features around the world, including populated places. They offer both free and paid premium data. Each feature is unique identified by a geonameId, which is an integer.

Many of the records returned by the GeoIP2 web services and databases include a geonameId property. This is the ID of a geographical feature (city, region, country, etc.) in the GeoNames database.

Some of the data that MaxMind provides is also sourced from GeoNames. We source things like place names, ISO codes, and other similar data from the GeoNames premium data set.

Reporting data problems

If the problem you find is that an IP address is incorrectly mapped, please submit your correction to MaxMind.

If you find some other sort of mistake, like an incorrect spelling, please check the GeoNames site first. Once you've searched for a place and found it on the GeoNames map view, there are a number of links you can use to correct data ("move", "edit", "alternate names", etc.). Once the correction is part of the GeoNames data set, it will be automatically incorporated into future MaxMind releases.

If you are a paying MaxMind customer and you're not sure where to submit a correction, please contact MaxMind support for help.

Other Support

Please report all issues with this code using the GitHub issue tracker.

If you are having an issue with a MaxMind service that is not specific to the client API, please see our support page.

Requirements

This library requires PHP 8.1 or greater.

This library also relies on the MaxMind DB Reader.

Contributing

Patches and pull requests are encouraged. All code should follow the PSR-2 style guidelines. Please include unit tests whenever possible. You may obtain the test data for the maxmind-db folder by running git submodule update --init --recursive or adding --recursive to your initial clone, or from https://github.com/maxmind/MaxMind-DB

Versioning

The GeoIP2 PHP API uses Semantic Versioning.

Copyright and License

This software is Copyright (c) 2013-2023 by MaxMind, Inc.

This is free software, licensed under the Apache License, Version 2.0.


All versions of geoip2 with dependencies

PHP Build Version
Package Version
Requires maxmind-db/reader Version ^1.11.1
maxmind/web-service-common Version ~0.8
php Version >=8.1
ext-json Version *
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 geoip2/geoip2 contains the following files

Loading the files please wait ....