1- # GeoIP2 PHP API #
1+ # GeoIP2 PHP API
22
3- ## Description ##
3+ ## Description
44
55This package provides an API for the GeoIP2 and GeoLite2
66[ web services] ( https://dev.maxmind.com/geoip/docs/web-services?lang=en ) and
77[ databases] ( https://dev.maxmind.com/geoip/docs/databases?lang=en ) .
88
9- ## Install via Composer ##
9+ ## Install via Composer
1010
11- We recommend installing this package with [ Composer] ( https://getcomposer.org/ ) .
11+ We recommend installing this package with
12+ [ Composer] ( https://getcomposer.org/ ) .
1213
13- ### Download Composer ###
14+ ### Download Composer
1415
1516To download Composer, run in the root directory of your project:
1617
@@ -20,7 +21,7 @@ curl -sS https://getcomposer.org/installer | php
2021
2122You should now have the file ` composer.phar ` in your project directory.
2223
23- ### Install Dependencies ###
24+ ### Install Dependencies
2425
2526Run in your project root:
2627
@@ -32,7 +33,7 @@ You should now have the files `composer.json` and `composer.lock` as well as
3233the directory ` vendor ` in your project directory. If you use a version control
3334system, ` composer.json ` should be added to it.
3435
35- ### Require Autoloader ###
36+ ### Require Autoloader
3637
3738After installing the dependencies, you need to require the Composer autoloader
3839from your code:
@@ -41,41 +42,41 @@ from your code:
4142require 'vendor/autoload.php';
4243```
4344
44- ## Install via Phar ##
45+ ## Install via Phar
4546
4647Although we strongly recommend using Composer, we also provide a
4748[ phar archive] ( https://php.net/manual/en/book.phar.php ) containing most of the
4849dependencies for GeoIP2. Our latest phar archive is available on
4950[ our releases page] ( https://github.com/maxmind/GeoIP2-php/releases ) .
5051
51- ### Install Dependencies ###
52+ ### Install Dependencies
5253
5354In order to use the phar archive, you must have the PHP
5455[ Phar extension] ( https://php.net/manual/en/book.phar.php ) installed and
5556enabled.
5657
5758If you will be making web service requests, you must have the PHP
58- [ cURL extension] ( https://php.net/manual/en/book.curl.php )
59- installed to use this archive. For Debian based distributions, this can
60- typically be found in the the ` php-curl ` package. For other operating
61- systems, please consult the relevant documentation. After installing the
62- extension you may need to restart your web server.
59+ [ cURL extension] ( https://php.net/manual/en/book.curl.php ) installed to use
60+ this archive. For Debian- based distributions, this can typically be found in
61+ the ` php-curl ` package. For other operating systems, please consult the
62+ relevant documentation. After installing the extension you may need to restart
63+ your web server.
6364
6465If you are missing this extension, you will see errors like the following:
6566
6667```
6768PHP Fatal error: Uncaught Error: Call to undefined function MaxMind\WebService\curl_version()
6869```
6970
70- ### Require Package ###
71+ ### Require Package
7172
7273To use the archive, just require it from your script:
7374
7475``` php
7576require 'geoip2.phar';
7677```
7778
78- ## Optional C Extension ##
79+ ## Optional C Extension
7980
8081The [ MaxMind DB API] ( https://github.com/maxmind/MaxMind-DB-Reader-php )
8182includes an optional C extension that you may install to dramatically increase
@@ -84,33 +85,33 @@ follow the instructions included with that API.
8485
8586The extension has no effect on web-service lookups.
8687
87- ## IP Geolocation Usage ##
88+ ## IP Geolocation Usage
8889
8990IP geolocation is inherently imprecise. Locations are often near the center of
9091the population. Any location provided by a GeoIP2 database or web service
9192should not be used to identify a particular address or household.
9293
93- ## Database Reader ##
94+ ## Database Reader
9495
95- ### Usage ###
96+ ### Usage
9697
9798To use this API, you must create a new ` \GeoIp2\Database\Reader ` object with
9899the path to the database file as the first argument to the constructor. You
99100may then call the method corresponding to the database you are using.
100101
101102If the lookup succeeds, the method call will return a model class for the
102- record in the database. This model in turn contains multiple container
103- classes for the different parts of the data such as the city in which the
104- IP address is located.
103+ record in the database. This model in turn contains multiple container classes
104+ for the different parts of the data such as the city in which the IP address
105+ is located.
105106
106- If the record is not found, a ` \GeoIp2\Exception\AddressNotFoundException `
107- is thrown. If the database is invalid or corrupt, a
107+ If the record is not found, a ` \GeoIp2\Exception\AddressNotFoundException ` is
108+ thrown. If the database is invalid or corrupt, a
108109` \MaxMind\Db\InvalidDatabaseException ` will be thrown.
109110
110111See the [ API documentation] ( https://maxmind.github.io/GeoIP2-php/ ) for more
111112details.
112113
113- ### City Example ###
114+ ### City Example
114115
115116``` php
116117<?php
@@ -143,7 +144,7 @@ print($record->traits->network . "\n"); // '128.101.101.101/32'
143144
144145```
145146
146- ### Anonymous IP Example ###
147+ ### Anonymous IP Example
147148
148149``` php
149150<?php
@@ -162,7 +163,7 @@ print($record->network . "\n"); // '128.101.101.101/32'
162163
163164```
164165
165- ### Anonymous Plus Example ###
166+ ### Anonymous Plus Example
166167
167168``` php
168169<?php
@@ -173,7 +174,7 @@ use GeoIp2\Database\Reader;
173174// lookups.
174175$anonymousDbReader = new Reader('/usr/local/share/GeoIP/GeoIP-Anonymous-Plus.mmdb');
175176
176- $record = $anonymousDbReader->anonymousIp ('203.0.113.0');
177+ $record = $anonymousDbReader->anonymousPlus ('203.0.113.0');
177178
178179print($record->anonymizerConfidence . "\n"); // 30
179180print($record->networkLastSeen . "\n"); // '2025-04-14'
@@ -184,7 +185,7 @@ print($record->network . "\n"); // '203.0.113.0/32'
184185
185186```
186187
187- ### Connection-Type Example ###
188+ ### Connection-Type Example
188189
189190``` php
190191<?php
@@ -203,7 +204,7 @@ print($record->network . "\n"); // '128.101.101.101/32'
203204
204205```
205206
206- ### Domain Example ###
207+ ### Domain Example
207208
208209``` php
209210<?php
@@ -222,7 +223,7 @@ print($record->network . "\n"); // '128.101.101.101/32'
222223
223224```
224225
225- ### Enterprise Example ###
226+ ### Enterprise Example
226227
227228``` php
228229<?php
@@ -258,7 +259,7 @@ print($record->traits->network . "\n"); // '128.101.101.101/32'
258259
259260```
260261
261- ### ISP Example ###
262+ ### ISP Example
262263
263264``` php
264265<?php
@@ -281,28 +282,27 @@ print($record->network . "\n"); // '128.101.101.101/32'
281282
282283```
283284
284- ## Database Updates ##
285+ ## Database Updates
285286
286287You can keep your databases up to date with our
287288[ GeoIP Update program] ( https://github.com/maxmind/geoipupdate/releases ) .
288- [ Learn more about GeoIP Update on our developer
289- portal.] ( https://dev.maxmind.com/geoip/updating-databases?lang=en )
289+ [ Learn more about GeoIP Update on our developer portal.] ( https://dev.maxmind.com/geoip/updating-databases?lang=en )
290290
291- ## Web Service Client ##
291+ ## Web Service Client
292292
293- ### Usage ###
293+ ### Usage
294294
295- To use this API, you must create a new ` \GeoIp2\WebService\Client `
296- object with your ` $accountId ` and ` $licenseKey ` :
295+ To use this API, you must create a new ` \GeoIp2\WebService\Client ` object with
296+ your ` $accountId ` and ` $licenseKey ` :
297297
298298``` php
299299$client = new Client(42, 'abcdef123456');
300300```
301301
302- You may also call the constructor with additional arguments. The third argument
303- specifies the language preferences when using the ` ->name ` method on the model
304- classes that this client creates. The fourth argument is additional options
305- such as ` host ` and ` timeout ` .
302+ You may also call the constructor with additional arguments. The third
303+ argument specifies the language preferences when using the ` ->name ` method on
304+ the model classes that this client creates. The fourth argument is additional
305+ options such as ` host ` and ` timeout ` .
306306
307307For instance, to call the GeoLite2 web service instead of the GeoIP2 web
308308service:
@@ -334,7 +334,7 @@ If there is an error, a structured exception is thrown.
334334See the [ API documentation] ( https://maxmind.github.io/GeoIP2-php/ ) for more
335335details.
336336
337- ### Example ###
337+ ### Example
338338
339339``` php
340340<?php
@@ -372,99 +372,98 @@ print($record->traits->network . "\n"); // '128.101.101.101/32'
372372
373373```
374374
375- ## Values to use for Database or Array Keys ##
375+ ## Values to use for Database or Array Keys
376376
377- ** We strongly discourage you from using a value from any ` names ` property as
378- a key in a database or array.**
377+ ** We strongly discourage you from using a value from any ` names ` property as a
378+ key in a database or array.**
379379
380380These names may change between releases. Instead we recommend using one of the
381381following:
382382
383- * ` GeoIp2\Record\City ` - ` $city->geonameId `
384- * ` GeoIp2\Record\Continent ` - ` $continent->code ` or ` $continent->geonameId `
385- * ` GeoIp2\Record\Country ` and ` GeoIp2\Record\RepresentedCountry ` -
383+ - ` GeoIp2\Record\City ` - ` $city->geonameId `
384+ - ` GeoIp2\Record\Continent ` - ` $continent->code ` or ` $continent->geonameId `
385+ - ` GeoIp2\Record\Country ` and ` GeoIp2\Record\RepresentedCountry ` -
386386 ` $country->isoCode ` or ` $country->geonameId `
387- * ` GeoIp2\Record\Subdivision ` - ` $subdivision->isoCode ` or ` $subdivision->geonameId `
387+ - ` GeoIp2\Record\Subdivision ` - ` $subdivision->isoCode ` or
388+ ` $subdivision->geonameId `
388389
389- ### What data is returned? ###
390+ ### What data is returned?
390391
391- While many of the end points return the same basic records, the attributes
392- which can be populated vary between end points . In addition, while an end
393- point may offer a particular piece of data, MaxMind does not always have every
394- piece of data for any given IP address.
392+ While many of the endpoints return the same basic records, the attributes
393+ which can be populated vary between endpoints . In addition, while an endpoint
394+ may offer a particular piece of data, MaxMind does not always have every piece
395+ of data for any given IP address.
395396
396- Because of these factors, it is possible for any end point to return a record
397+ Because of these factors, it is possible for any endpoint to return a record
397398where some or all of the attributes are unpopulated.
398399
399400See the
400401[ GeoIP2 web service docs] ( https://dev.maxmind.com/geoip/docs/web-services?lang=en )
401- for details on what data each end point may return.
402+ for details on what data each endpoint may return.
402403
403- The only piece of data which is always returned is the ` ipAddress `
404- attribute in the ` GeoIp2\Record\Traits ` record.
404+ The only piece of data which is always returned is the ` ipAddress ` attribute
405+ in the ` GeoIp2\Record\Traits ` record.
405406
406- ## Integration with GeoNames ##
407+ ## Integration with GeoNames
407408
408409[ GeoNames] ( https://www.geonames.org/ ) offers web services and downloadable
409410databases with data on geographical features around the world, including
410- populated places. They offer both free and paid premium data. Each
411- feature is unique identified by a ` geonameId ` , which is an integer.
411+ populated places. They offer both free and paid premium data. Each feature is
412+ uniquely identified by a ` geonameId ` , which is an integer.
412413
413- Many of the records returned by the GeoIP2 web services and databases
414- include a ` geonameId ` property. This is the ID of a geographical feature
415- (city, region, country, etc.) in the GeoNames database.
414+ Many of the records returned by the GeoIP2 web services and databases include
415+ a ` geonameId ` property. This is the ID of a geographical feature (city,
416+ region, country, etc.) in the GeoNames database.
416417
417418Some of the data that MaxMind provides is also sourced from GeoNames. We
418- source things like place names, ISO codes, and other similar data from
419- the GeoNames premium data set.
419+ source things like place names, ISO codes, and other similar data from the
420+ GeoNames premium data set.
420421
421- ## Reporting data problems ##
422+ ## Reporting data problems
422423
423- If the problem you find is that an IP address is incorrectly mapped,
424- please
424+ If the problem you find is that an IP address is incorrectly mapped, please
425425[ submit your correction to MaxMind] ( https://www.maxmind.com/en/correction ) .
426426
427- If you find some other sort of mistake, like an incorrect spelling,
428- please check the [ GeoNames site] ( https://www.geonames.org/ ) first. Once
429- you've searched for a place and found it on the GeoNames map view, there
430- are a number of links you can use to correct data ("move", "edit",
431- "alternate names", etc.). Once the correction is part of the GeoNames
432- data set, it will be automatically incorporated into future MaxMind
433- releases.
427+ If you find some other sort of mistake, like an incorrect spelling, please
428+ check the [ GeoNames site] ( https://www.geonames.org/ ) first. Once you've
429+ searched for a place and found it on the GeoNames map view, there are a number
430+ of links you can use to correct data ("move", "edit", "alternate names",
431+ etc.). Once the correction is part of the GeoNames data set, it will be
432+ automatically incorporated into future MaxMind releases.
434433
435- If you are a paying MaxMind customer and you're not sure where to submit
436- a correction, please
434+ If you are a paying MaxMind customer and you're not sure where to submit a
435+ correction, please
437436[ contact MaxMind support] ( https://www.maxmind.com/en/support ) for help.
438437
439- ## Other Support ##
438+ ## Other Support
440439
441440Please report all issues with this code using the
442441[ GitHub issue tracker] ( https://github.com/maxmind/GeoIP2-php/issues ) .
443442
444- If you are having an issue with a MaxMind service that is not specific
445- to the client API, please see
446- [ our support page] ( https://www.maxmind.com/en/support ) .
443+ If you are having an issue with a MaxMind service that is not specific to the
444+ client API, please see [ our support page] ( https://www.maxmind.com/en/support ) .
447445
448- ## Requirements ##
446+ ## Requirements
449447
450448This library requires PHP 8.1 or greater.
451449
452- This library also relies on the [ MaxMind DB Reader] ( https://github.com/maxmind/MaxMind-DB-Reader-php ) .
450+ This library also relies on the
451+ [ MaxMind DB Reader] ( https://github.com/maxmind/MaxMind-DB-Reader-php ) .
453452
454- ## Contributing ##
453+ ## Contributing
455454
456- Patches and pull requests are encouraged. All code should follow the PSR-2
455+ Patches and pull requests are encouraged. All code should follow the PSR-12
457456style guidelines. Please include unit tests whenever possible. You may obtain
458- the test data for the maxmind-db folder by running `git submodule update
459- --init --recursive` or adding ` --recursive` to your initial clone, or from
460- https://github.com/maxmind/MaxMind-DB
457+ the test data for the maxmind-db folder by running
458+ ` git submodule update --init --recursive` or adding ` --recursive ` to your
459+ initial clone, or from https://github.com/maxmind/MaxMind-DB
461460
462- ## Versioning ##
461+ ## Versioning
463462
464463The GeoIP2 PHP API uses [ Semantic Versioning] ( https://semver.org/ ) .
465464
466- ## Copyright and License ##
465+ ## Copyright and License
467466
468- This software is Copyright (c) 2013-2025 by MaxMind, Inc.
467+ This software is Copyright (c) 2013-2026 by MaxMind, Inc.
469468
470469This is free software, licensed under the Apache License, Version 2.0.
0 commit comments