Skip to content

Commit aefa9df

Browse files
committed
GeoIP2 v0.9.0 PHP Extension
0 parents  commit aefa9df

File tree

176 files changed

+22684
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+22684
-0
lines changed

.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.idea
2+
*.iml
3+
.DS_*
4+
5+
# Cache files
6+
.temp/
7+
.libs/
8+
9+
# Object files
10+
*.lo
11+
*.la
12+
*.o
13+
*.loT
14+
15+
# Files generated by configure,
16+
# not required for extension compilation.
17+
ext/build/
18+
ext/modules/
19+
ext/Makefile*
20+
ext/config*
21+
ext/acinclude.m4
22+
ext/aclocal.m4
23+
ext/autom4te*
24+
ext/install-sh
25+
ext/ltmain.sh
26+
ext/missing
27+
ext/mkinstalldirs
28+
ext/run-tests.php
29+
ext/.deps
30+
ext/libtool

README.md

+271
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
# PHP GeoIP2 extension #
2+
3+
## Description ##
4+
5+
This package provides an API for the GeoIP2
6+
[databases](http://dev.maxmind.com/geoip/geoip2/downloadable). The API also
7+
works with the free
8+
[GeoLite2 databases](http://dev.maxmind.com/geoip/geoip2/geolite2/).
9+
10+
### Dependencies ###
11+
12+
This extension depends on:
13+
14+
```
15+
php-maxminddb
16+
php-json
17+
```
18+
19+
## IP Geolocation Usage ##
20+
21+
IP geolocation is inherently imprecise. Locations are often near the center of
22+
the population. Any location provided by a GeoIP2 database or web service
23+
should not be used to identify a particular address or household.
24+
25+
## Database Reader ##
26+
27+
### Usage ###
28+
29+
To use this API, you must create a new `\GeoIP2\Database\Reader` object with
30+
the path to the database file as the first argument to the constructor. You
31+
may then call the method corresponding to the database you are using.
32+
33+
If the lookup succeeds, the method call will return a model class for the
34+
record in the database. This model in turn contains multiple container
35+
classes for the different parts of the data such as the city in which the
36+
IP address is located.
37+
38+
If the record is not found, a `\GeoIP2\Exception\AddressNotFoundException`
39+
is thrown. If the database is invalid or corrupt, a
40+
`\GeoIP2\Exception\InvalidDatabaseException` will be thrown.
41+
42+
See the API documentation for more details.
43+
44+
### City Example ###
45+
46+
```php
47+
<?php
48+
49+
use GeoIP2\Database\Reader;
50+
51+
// This creates the Reader object, which should be reused across
52+
// lookups.
53+
$reader = new Reader('/usr/share/GeoIP/GeoIP2-City.mmdb');
54+
55+
// Replace "city" with the appropriate method for your database, e.g.,
56+
// "country".
57+
$record = $reader->city('128.101.101.101');
58+
59+
print($record->country->isoCode . "\n"); // 'US'
60+
print($record->country->name . "\n"); // 'United States'
61+
print($record->country->names['zh-CN'] . "\n"); // '美国'
62+
63+
print($record->mostSpecificSubdivision->name . "\n"); // 'Minnesota'
64+
print($record->mostSpecificSubdivision->isoCode . "\n"); // 'MN'
65+
66+
print($record->city->name . "\n"); // 'Minneapolis'
67+
68+
print($record->postal->code . "\n"); // '55455'
69+
70+
print($record->location->latitude . "\n"); // 44.9733
71+
print($record->location->longitude . "\n"); // -93.2323
72+
73+
```
74+
75+
### Anonymous IP Example ###
76+
77+
```php
78+
<?php
79+
80+
use GeoIP2\Database\Reader;
81+
82+
// This creates the Reader object, which should be reused across
83+
// lookups.
84+
$reader = new Reader('/usr/share/GeoIP/GeoIP2-Anonymous-IP.mmdb');
85+
86+
$record = $reader->anonymousIp('128.101.101.101');
87+
88+
if ($record->isAnonymous) { print "anon\n"; }
89+
print($record->ipAddress . "\n"); // '128.101.101.101'
90+
91+
```
92+
93+
### Connection-Type Example ###
94+
95+
```php
96+
<?php
97+
98+
use GeoIP2\Database\Reader;
99+
100+
// This creates the Reader object, which should be reused across
101+
// lookups.
102+
$reader = new Reader('/usr/share/GeoIP/GeoIP2-Connection-Type.mmdb');
103+
104+
$record = $reader->connectionType('128.101.101.101');
105+
106+
print($record->connectionType . "\n"); // 'Corporate'
107+
print($record->ipAddress . "\n"); // '128.101.101.101'
108+
109+
```
110+
111+
### Domain Example ###
112+
113+
```php
114+
<?php
115+
116+
use GeoIP2\Database\Reader;
117+
118+
// This creates the Reader object, which should be reused across
119+
// lookups.
120+
$reader = new Reader('/usr/share/GeoIP/GeoIP2-Domain.mmdb');
121+
122+
$record = $reader->domain('128.101.101.101');
123+
124+
print($record->domain . "\n"); // 'umn.edu'
125+
print($record->ipAddress . "\n"); // '128.101.101.101'
126+
127+
```
128+
129+
### Enterprise Example ###
130+
131+
```php
132+
<?php
133+
134+
use GeoIP2\Database\Reader;
135+
136+
// This creates the Reader object, which should be reused across
137+
// lookups.
138+
$reader = new Reader('/usr/share/GeoIP/GeoIP2-Enterprise.mmdb');
139+
140+
// Use the ->enterprise method to do a lookup in the Enterprise database
141+
$record = $reader->enterprise('128.101.101.101');
142+
143+
print($record->country->confidence . "\n"); // 99
144+
print($record->country->isoCode . "\n"); // 'US'
145+
print($record->country->name . "\n"); // 'United States'
146+
print($record->country->names['zh-CN'] . "\n"); // '美国'
147+
148+
print($record->mostSpecificSubdivision->confidence . "\n"); // 77
149+
print($record->mostSpecificSubdivision->name . "\n"); // 'Minnesota'
150+
print($record->mostSpecificSubdivision->isoCode . "\n"); // 'MN'
151+
152+
print($record->city->confidence . "\n"); // 60
153+
print($record->city->name . "\n"); // 'Minneapolis'
154+
155+
print($record->postal->code . "\n"); // '55455'
156+
157+
print($record->location->accuracyRadius . "\n"); // 50
158+
print($record->location->latitude . "\n"); // 44.9733
159+
print($record->location->longitude . "\n"); // -93.2323
160+
161+
```
162+
163+
### ISP Example ###
164+
165+
```php
166+
<?php
167+
168+
use GeoIP2\Database\Reader;
169+
170+
// This creates the Reader object, which should be reused across
171+
// lookups.
172+
$reader = new Reader('/usr/share/GeoIP/GeoIP2-ISP.mmdb');
173+
174+
$record = $reader->isp('128.101.101.101');
175+
176+
print($record->autonomousSystemNumber . "\n"); // 217
177+
print($record->autonomousSystemOrganization . "\n"); // 'University of Minnesota'
178+
print($record->isp . "\n"); // 'University of Minnesota'
179+
print($record->organization . "\n"); // 'University of Minnesota'
180+
181+
print($record->ipAddress . "\n"); // '128.101.101.101'
182+
183+
```
184+
185+
## Values to use for Database or Array Keys ##
186+
187+
**We strongly discourage you from using a value from any `names` property as
188+
a key in a database or array.**
189+
190+
These names may change between releases. Instead we recommend using one of the
191+
following:
192+
193+
* `GeoIP2\Record\City` - `$city->geonameId`
194+
* `GeoIP2\Record\Continent` - `$continent->code` or `$continent->geonameId`
195+
* `GeoIP2\Record\Country` and `GeoIP2\Record\RepresentedCountry` -
196+
`$country->isoCode` or `$country->geonameId`
197+
* `GeoIP2\Record\Subdivision` - `$subdivision->isoCode` or `$subdivision->geonameId`
198+
199+
### What data is returned? ###
200+
201+
While many of the end points return the same basic records, the attributes
202+
which can be populated vary between end points. In addition, while an end
203+
point may offer a particular piece of data, MaxMind does not always have every
204+
piece of data for any given IP address.
205+
206+
Because of these factors, it is possible for any end point to return a record
207+
where some or all of the attributes are unpopulated.
208+
209+
See the
210+
[GeoIP2 Precision web service docs](http://dev.maxmind.com/geoip/geoip2/web-services)
211+
for details on what data each end point may return.
212+
213+
The only piece of data which is always returned is the `ipAddress`
214+
attribute in the `GeoIP2\Record\Traits` record.
215+
216+
## Integration with GeoNames ##
217+
218+
[GeoNames](http://www.geonames.org/) offers web services and downloadable
219+
databases with data on geographical features around the world, including
220+
populated places. They offer both free and paid premium data. Each
221+
feature is unique identified by a `geonameId`, which is an integer.
222+
223+
Many of the records returned by the GeoIP2 web services and databases
224+
include a `geonameId` property. This is the ID of a geographical feature
225+
(city, region, country, etc.) in the GeoNames database.
226+
227+
Some of the data that MaxMind provides is also sourced from GeoNames. We
228+
source things like place names, ISO codes, and other similar data from
229+
the GeoNames premium data set.
230+
231+
## Reporting data problems ##
232+
233+
If the problem you find is that an IP address is incorrectly mapped,
234+
please
235+
[submit your correction to MaxMind](http://www.maxmind.com/en/correction).
236+
237+
If you find some other sort of mistake, like an incorrect spelling,
238+
please check the [GeoNames site](http://www.geonames.org/) first. Once
239+
you've searched for a place and found it on the GeoNames map view, there
240+
are a number of links you can use to correct data ("move", "edit",
241+
"alternate names", etc.). Once the correction is part of the GeoNames
242+
data set, it will be automatically incorporated into future MaxMind
243+
releases.
244+
245+
If you are a paying MaxMind customer and you're not sure where to submit
246+
a correction, please
247+
[contact MaxMind support](http://www.maxmind.com/en/support) for help.
248+
249+
## Other Support ##
250+
251+
Please report all issues with this code using the
252+
[GitHub issue tracker](https://github.com/php-extensions/php-geoip2/issues).
253+
254+
If you are having an issue with a MaxMind service that is not specific
255+
to the client API, please see
256+
[MaxMind support page](http://www.maxmind.com/en/support).
257+
258+
## Requirements ##
259+
260+
This library requires PHP 5.4 or greater.
261+
262+
This library also relies on the [MaxMind DB Reader](https://github.com/maxmind/MaxMind-DB-Reader-php).
263+
264+
## Contributing ##
265+
266+
Patches and pull requests are encouraged. All code should follow the PSR-2
267+
style guidelines. Please include unit tests whenever possible. You may obtain
268+
the test data for the maxmind-db folder by running `git submodule update
269+
--init --recursive` or adding `--recursive` to your initial clone, or from
270+
https://github.com/maxmind/MaxMind-DB
271+

config.json

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"stubs": {
3+
"path": "ide\/%version%\/%namespace%\/",
4+
"stubs-run-after-generate": false
5+
},
6+
"api": {
7+
"path": "doc\/%version%",
8+
"theme": {
9+
"name": "zephir",
10+
"options": {
11+
"github": null,
12+
"analytics": null,
13+
"main_color": "#3E6496",
14+
"link_color": "#3E6496",
15+
"link_hover_color": "#5F9AE7"
16+
}
17+
}
18+
},
19+
"warnings": {
20+
"unused-variable": true,
21+
"unused-variable-external": false,
22+
"possible-wrong-parameter": true,
23+
"possible-wrong-parameter-undefined": false,
24+
"nonexistent-function": true,
25+
"nonexistent-class": true,
26+
"non-valid-isset": true,
27+
"non-array-update": true,
28+
"non-valid-objectupdate": true,
29+
"non-valid-fetch": true,
30+
"invalid-array-index": true,
31+
"non-array-append": true,
32+
"invalid-return-type": true,
33+
"unreachable-code": true,
34+
"nonexistent-constant": true,
35+
"not-supported-magic-constant": true,
36+
"non-valid-decrement": true,
37+
"non-valid-increment": true,
38+
"non-valid-clone": true,
39+
"non-valid-new": true,
40+
"non-array-access": true,
41+
"invalid-reference": true,
42+
"invalid-typeof-comparison": true,
43+
"conditional-initialization": true
44+
},
45+
"optimizations": {
46+
"static-type-inference": true,
47+
"static-type-inference-second-pass": true,
48+
"local-context-pass": true,
49+
"constant-folding": true,
50+
"static-constant-class-folding": true,
51+
"call-gatherer-pass": true,
52+
"check-invalid-reads": false,
53+
"internal-call-transformation": false
54+
},
55+
"namespace": "geoip2",
56+
"name": "geoip2",
57+
"description": "GeoIP2 PHP API",
58+
"author": "github.com/php-extensions",
59+
"version": "0.9.0",
60+
"verbose": false,
61+
"requires": {
62+
"extensions": ["maxminddb", "json"]
63+
}
64+
}

doc/0.9.0/asset/api_definition.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/0.9.0/asset/static/jquery.min.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)