1
- # PHP GeoIP2 extension #
1
+ # PHP GeoIP2 extension
2
2
3
- ## Description ##
3
+ ## Description
4
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
5
+ This extension provides an API for the MaxMind
6
+ [ GeoIP2 databases] ( http://dev.maxmind.com/geoip/geoip2/downloadable ) and free
8
7
[ GeoLite2 databases] ( http://dev.maxmind.com/geoip/geoip2/geolite2/ ) .
9
8
10
- ### Dependencies ###
9
+ This extension is a port of the official [ MaxMind GeoIP2 PHP package] ( https://github.com/maxmind/GeoIP2-php )
10
+ and [ MaxMind DB Reader PHP package] ( https://github.com/maxmind/MaxMind-DB-Reader-php ) .
11
+ It is written in Zephir and converted to C.
11
12
12
- This extension depends on:
13
+ ### Requirements
14
+
15
+ Since version 0.9.2 this extension requires PHP 7 or greater.
16
+
17
+ ### Building extension
18
+
19
+ #### Prerequisites
20
+
21
+ Since version 0.9.2, gcc 7+ is required. To enable it on CentOS:
22
+
23
+ ```
24
+ yum install -y yum-utils centos-release-scl
25
+ yum -y --enablerepo=centos-sclo-rh-testing install devtoolset-7-gcc
26
+ echo "source /opt/rh/devtoolset-7/enable" | sudo tee -a /etc/profile
27
+ source /opt/rh/devtoolset-7/enable
28
+ ```
29
+
30
+ Building with Zephir (recommended)
13
31
14
32
```
15
- php-maxminddb
16
- php-json
33
+ zephir compile
34
+ zephir install
17
35
```
18
36
19
- ## IP Geolocation Usage ##
37
+ Building without Zephir
38
+
39
+ ```
40
+ cd ext
41
+ phpize
42
+ ./configure
43
+ make
44
+ make install
45
+ ```
46
+
47
+ This extension can also read custom databases created using
48
+ [ MaxMind DB Writer] ( https://github.com/maxmind/MaxMind-DB-Writer-perl] ) .
49
+
50
+ ```
51
+ use GeoIP2\Database\Reader;
52
+
53
+ $ipAddress = '8.8.8.8';
54
+ $databaseFile = 'mydb.mmdb';
55
+
56
+ $reader = new Reader($databaseFile);
57
+
58
+ print_r($record = $reader->custom($ipAddress));
59
+
60
+ print_r($record->raw['color']);
61
+ print_r($record->get('dogs'));
62
+ ```
63
+
64
+ ## IP Geolocation Usage
20
65
21
66
IP geolocation is inherently imprecise. Locations are often near the center of
22
67
the population. Any location provided by a GeoIP2 database or web service
23
68
should not be used to identify a particular address or household.
24
69
25
- ## Database Reader ##
70
+ ## Database Reader
26
71
27
- ### Usage ###
72
+ ### Usage
28
73
29
74
To use this API, you must create a new ` \GeoIP2\Database\Reader ` object with
30
75
the path to the database file as the first argument to the constructor. You
@@ -41,7 +86,7 @@ is thrown. If the database is invalid or corrupt, a
41
86
42
87
See the API documentation for more details.
43
88
44
- ### City Example ###
89
+ ### City Example
45
90
46
91
``` php
47
92
<?php
@@ -72,7 +117,7 @@ print($record->location->longitude . "\n"); // -93.2323
72
117
73
118
```
74
119
75
- ### Anonymous IP Example ###
120
+ ### Anonymous IP Example
76
121
77
122
``` php
78
123
<?php
@@ -90,7 +135,7 @@ print($record->ipAddress . "\n"); // '128.101.101.101'
90
135
91
136
```
92
137
93
- ### Connection-Type Example ###
138
+ ### Connection-Type Example
94
139
95
140
``` php
96
141
<?php
@@ -108,7 +153,7 @@ print($record->ipAddress . "\n"); // '128.101.101.101'
108
153
109
154
```
110
155
111
- ### Domain Example ###
156
+ ### Domain Example
112
157
113
158
``` php
114
159
<?php
@@ -126,7 +171,7 @@ print($record->ipAddress . "\n"); // '128.101.101.101'
126
171
127
172
```
128
173
129
- ### Enterprise Example ###
174
+ ### Enterprise Example
130
175
131
176
``` php
132
177
<?php
@@ -160,7 +205,7 @@ print($record->location->longitude . "\n"); // -93.2323
160
205
161
206
```
162
207
163
- ### ISP Example ###
208
+ ### ISP Example
164
209
165
210
``` php
166
211
<?php
@@ -182,7 +227,7 @@ print($record->ipAddress . "\n"); // '128.101.101.101'
182
227
183
228
```
184
229
185
- ## Values to use for Database or Array Keys ##
230
+ ## Values to use for Database or Array Keys
186
231
187
232
** We strongly discourage you from using a value from any ` names ` property as
188
233
a key in a database or array.**
@@ -196,7 +241,7 @@ following:
196
241
` $country->isoCode ` or ` $country->geonameId `
197
242
* ` GeoIP2\Record\Subdivision ` - ` $subdivision->isoCode ` or ` $subdivision->geonameId `
198
243
199
- ### What data is returned? ###
244
+ ### What data is returned?
200
245
201
246
While many of the end points return the same basic records, the attributes
202
247
which can be populated vary between end points. In addition, while an end
@@ -213,7 +258,7 @@ for details on what data each end point may return.
213
258
The only piece of data which is always returned is the ` ipAddress `
214
259
attribute in the ` GeoIP2\Record\Traits ` record.
215
260
216
- ## Integration with GeoNames ##
261
+ ## Integration with GeoNames
217
262
218
263
[ GeoNames] ( http://www.geonames.org/ ) offers web services and downloadable
219
264
databases with data on geographical features around the world, including
@@ -228,7 +273,7 @@ Some of the data that MaxMind provides is also sourced from GeoNames. We
228
273
source things like place names, ISO codes, and other similar data from
229
274
the GeoNames premium data set.
230
275
231
- ## Reporting data problems ##
276
+ ## Reporting data problems
232
277
233
278
If the problem you find is that an IP address is incorrectly mapped,
234
279
please
@@ -246,26 +291,11 @@ If you are a paying MaxMind customer and you're not sure where to submit
246
291
a correction, please
247
292
[ contact MaxMind support] ( http://www.maxmind.com/en/support ) for help.
248
293
249
- ## Other Support ##
294
+ ## Other Support
250
295
251
296
Please report all issues with this code using the
252
297
[ GitHub issue tracker] ( https://github.com/php-extensions/php-geoip2/issues ) .
253
298
254
299
If you are having an issue with a MaxMind service that is not specific
255
300
to the client API, please see
256
301
[ 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
-
0 commit comments