├── ChangeLog.md
├── tests
├── data
│ ├── GeoIP.dat
│ ├── GeoIPISP.dat
│ ├── GeoIPOrg.dat
│ ├── GeoIPv6.dat
│ ├── GeoIPASNum.dat
│ ├── GeoIPCity.dat
│ ├── GeoIPDomain.dat
│ ├── GeoIPRegion.dat
│ ├── GeoLiteCityIPv6.dat
│ └── GeoIPNetSpeedCell.dat
├── bootstrap.php
├── OrgTest.php
├── DomainTest.php
├── NetspeedcellTest.php
├── RegionTest.php
├── CountryTest.php
└── CityTest.php
├── timezone
├── test_timezone.php
└── make_time_zone_php_code.pl
├── .gitignore
├── examples
├── netspeedcell.php
├── domain.php
├── asn-v6.php
├── country.php
├── org.php
├── netspeed.php
├── region.php
├── city.php
├── country-v6.php
├── city-v6.php
└── benchmark.php
├── .travis.yml
├── composer.json
├── phpunit.xml.dist
├── admin
└── build_geoipregionvars.php
├── README.md
├── src
├── geoipcity.inc
├── geoip.inc
└── timezone.php
└── LICENSE
/ChangeLog.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/ChangeLog.md
--------------------------------------------------------------------------------
/tests/data/GeoIP.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/tests/data/GeoIP.dat
--------------------------------------------------------------------------------
/tests/data/GeoIPISP.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/tests/data/GeoIPISP.dat
--------------------------------------------------------------------------------
/tests/data/GeoIPOrg.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/tests/data/GeoIPOrg.dat
--------------------------------------------------------------------------------
/tests/data/GeoIPv6.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/tests/data/GeoIPv6.dat
--------------------------------------------------------------------------------
/tests/data/GeoIPASNum.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/tests/data/GeoIPASNum.dat
--------------------------------------------------------------------------------
/tests/data/GeoIPCity.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/tests/data/GeoIPCity.dat
--------------------------------------------------------------------------------
/tests/data/GeoIPDomain.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/tests/data/GeoIPDomain.dat
--------------------------------------------------------------------------------
/tests/data/GeoIPRegion.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/tests/data/GeoIPRegion.dat
--------------------------------------------------------------------------------
/tests/data/GeoLiteCityIPv6.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/tests/data/GeoLiteCityIPv6.dat
--------------------------------------------------------------------------------
/tests/data/GeoIPNetSpeedCell.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chapagain/geoip-api-php/master/tests/data/GeoIPNetSpeedCell.dat
--------------------------------------------------------------------------------
/timezone/test_timezone.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | _site
2 | .gh-pages
3 | composer.lock
4 | composer.phar
5 | phpunit.xml
6 | vendor/
7 | *.sw?
8 | t.php
9 | *.old
10 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 |
15 |
--------------------------------------------------------------------------------
/tests/OrgTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(
10 | 'AT&T Worldnet Services',
11 | geoip_org_by_addr($gi, "12.87.118.0")
12 | );
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/tests/DomainTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(
11 | 'shoesfin.NET',
12 | geoip_org_by_addr($gi, "67.43.156.0")
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/tests/NetspeedcellTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(
10 | 'Dialup',
11 | geoip_org_by_addr($gi, "2.125.160.1")
12 | );
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/examples/domain.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 |
17 |
--------------------------------------------------------------------------------
/examples/asn-v6.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 |
18 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 5.3
5 | - 5.4
6 | - 5.5
7 | - 5.6
8 | - hhvm
9 |
10 | matrix:
11 | allow_failures:
12 | - php: hhvm
13 |
14 | before_install:
15 | - composer self-update
16 | - composer install --dev -n --prefer-source
17 | - phpenv rehash
18 | - mkdir -p build/logs
19 |
20 | script:
21 | - phpunit -c phpunit.xml.dist
22 |
23 | after_script:
24 | - php vendor/bin/coveralls
25 |
26 | notifications:
27 | email:
28 | recipients:
29 | - dev@maxmind.com
30 | on_success: change
31 | on_failure: always
32 |
--------------------------------------------------------------------------------
/examples/country.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 |
21 |
--------------------------------------------------------------------------------
/tests/RegionTest.php:
--------------------------------------------------------------------------------
1 | assertEquals('CA', $region);
15 | $this->assertEquals('US', $countryCode);
16 |
17 | global $GEOIP_REGION_NAME;
18 | $this->assertEquals(
19 | 'California',
20 | $GEOIP_REGION_NAME[$countryCode][$region]
21 | );
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/org.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 |
23 |
--------------------------------------------------------------------------------
/examples/netspeed.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 |
30 |
--------------------------------------------------------------------------------
/tests/CountryTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(
11 | 'US',
12 | geoip_country_code_by_addr($gi, '64.17.254.216')
13 | );
14 | $this->assertEquals(
15 | 'United States',
16 | geoip_country_name_by_addr($gi, '64.17.254.216')
17 | );
18 | }
19 |
20 | public function testV6()
21 | {
22 | $gi = geoip_open("tests/data/GeoIPv6.dat", GEOIP_STANDARD);
23 |
24 | $this->assertEquals(
25 | 'JP',
26 | geoip_country_code_by_addr_v6($gi, '2001:200::')
27 | );
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "geoip/geoip",
3 | "description": "MaxMind GeoIP PHP API",
4 | "keywords": [ "geoip", "geolocation", "maxmind" ],
5 | "homepage": "http://dev.maxmind.com/geoip/legacy/downloadable",
6 | "type": "library",
7 | "license": "LGPL 2.1+",
8 | "authors": [
9 | {
10 | "name": "MaxMind, Inc.",
11 | "email": "support@maxmind.com",
12 | "homepage": "http://www.maxmind.com/"
13 | }
14 | ],
15 | "autoload": {
16 | "files": [
17 | "src/geoip.inc",
18 | "src/geoipcity.inc",
19 | "src/timezone.php"
20 | ]
21 | },
22 | "conflict": {
23 | "ext-geoip": "*"
24 | },
25 | "require-dev": {
26 | "phpunit/phpunit": "3.7.*",
27 | "satooshi/php-coveralls": "dev-master"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/examples/region.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 |
21 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ./tests
7 |
8 |
9 |
10 |
11 |
12 | ./src
13 | ./src
14 |
15 |
16 | ./build
17 | ./composer
18 | ./tests
19 | ./travis
20 | ./vendor
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/admin/build_geoipregionvars.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 | country_code . " " . $record->country_code3 . " " . $record->country_name . "\n";
22 | print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n";
23 | print $record->city . "\n";
24 | print $record->postal_code . "\n";
25 | print $record->latitude . "\n";
26 | print $record->longitude . "\n";
27 | print $record->metro_code . "\n";
28 | print $record->area_code . "\n";
29 | print $record->continent_code . "\n";
30 |
31 | geoip_close($gi);
32 |
33 | ?>
34 |
--------------------------------------------------------------------------------
/examples/country-v6.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 |
33 |
--------------------------------------------------------------------------------
/examples/city-v6.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 | country_code . " " . $record->country_code3 . " " . $record->country_name . "\n";
22 | print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n";
23 | print $record->city . "\n";
24 | print $record->postal_code . "\n";
25 | print $record->latitude . "\n";
26 | print $record->longitude . "\n";
27 | print $record->metro_code . "\n";
28 | print $record->area_code . "\n";
29 | print $record->continent_code . "\n";
30 |
31 | geoip_close($gi);
32 |
33 | ?>
34 |
--------------------------------------------------------------------------------
/tests/CityTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(310, $record->area_code);
15 | $this->assertEquals('El Segundo', $record->city);
16 | $this->assertEquals('US', $record->country_code);
17 | $this->assertEquals('USA', $record->country_code3);
18 | $this->assertEquals('United States', $record->country_name);
19 | $this->assertEquals(803, $record->dma_code);
20 | $this->assertEquals(33.91, $record->latitude, '', 0.01);
21 | $this->assertEquals(-118.40, $record->longitude, '', 0.01);
22 | $this->assertEquals(803, $record->metro_code);
23 | $this->assertEquals('90245', $record->postal_code);
24 | $this->assertEquals('CA', $record->region);
25 | $this->assertEquals(
26 | 'California',
27 | $GEOIP_REGION_NAME[$record->country_code][$record->region]
28 | );
29 | $this->assertEquals(
30 | 'America/Los_Angeles',
31 | get_time_zone($record->country_code, $record->region)
32 | );
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/timezone/make_time_zone_php_code.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use strict;
4 | use warnings;
5 |
6 | use HTTP::Tiny;
7 | use Text::CSV_XS;
8 |
9 | my $old_country = q{};
10 | my $old_region = q{};
11 |
12 | my $response = HTTP::Tiny->new->get(
13 | 'http://dev.maxmind.com/static/csv/codes/time_zone.csv');
14 |
15 | die "Failed to download CSV!\n" unless $response->{success};
16 |
17 | print <<'EOF';
18 | new ({ binary => 1});
33 |
34 | my @timezones = split /\n/, $response->{content};
35 | shift @timezones;
36 |
37 | for my $line (@timezones) {
38 | $csv->parse($line) or die $csv->error_diag();
39 | my ( $country, $region, $timezone ) = $csv->fields;
40 |
41 | if ( $country ne $old_country ) {
42 | if ( $old_region ne q{} ) {
43 | print " }\n";
44 | print " break;\n";
45 | }
46 | print ' case "' . $country . q(") . ":\n";
47 | if ( $region ne q{} ) {
48 | print " switch (\$region) {\n";
49 | }
50 | }
51 | if ( $region ne q{} ) {
52 | print ' case "' . $region . q(") . ":\n ";
53 | }
54 | print ' $timezone = "' . $timezone . q(") . ";\n";
55 | if ( $region ne q{} ) {
56 | print " break;\n";
57 | }
58 | else {
59 | print " break;\n";
60 | }
61 | $old_country = $country;
62 | $old_region = $region;
63 | }
64 | print " }\n";
65 | print " return \$timezone;\n";
66 |
67 | print "}\n";
68 |
69 |
--------------------------------------------------------------------------------
/examples/benchmark.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/php -q
2 | 0) {
25 | $result = $result . ".";
26 | }
27 | $a2 = rand(1, 254);
28 | $result = $result . $a2;
29 | }
30 | return $result;
31 | }
32 |
33 | public function testgeoipdatabase($type, $flags, $msg, $numlookups)
34 | {
35 | $gi = geoip_open($this->dbfilename[$type], $flags);
36 | if ($gi == null) {
37 | print "error: " . $this->dbfilename[$type] . " does not exist\n";
38 | return;
39 | }
40 | $startTime = microtime(true);
41 | for ($i2 = 0; $i2 < $numlookups; $i2++) {
42 | switch ($type) {
43 | case GEOIP_COUNTRY_DATABASE:
44 | geoip_country_code_by_addr($gi, $this->randomipaddress());
45 | break;
46 | case GEOIP_REGION_DATABASE:
47 | geoip_region_by_addr($gi, $this->randomipaddress());
48 | break;
49 | case GEOIP_CITY_DATABASE:
50 | GeoIP_record_by_addr($gi, $this->randomipaddress());
51 | break;
52 | }
53 | }
54 | $duration = microtime(true) - $startTime;
55 | print $msg . "\n";
56 | print $numlookups . " lookups made in " . $duration . " seconds \n";
57 | geoip_close($gi);
58 | }
59 | }
60 |
61 |
62 | $mainapp = new mainappc();
63 |
64 |
65 | $mainapp->testgeoipdatabase(GEOIP_COUNTRY_DATABASE, GEOIP_STANDARD, "Geoip Country ", 10000);
66 | $mainapp->testgeoipdatabase(GEOIP_COUNTRY_DATABASE, GEOIP_MEMORY_CACHE, "Geoip Country with memory cache", 10000);
67 | $mainapp->testgeoipdatabase(GEOIP_REGION_DATABASE, GEOIP_STANDARD, "Geoip Region ", 10000);
68 | $mainapp->testgeoipdatabase(GEOIP_REGION_DATABASE, GEOIP_MEMORY_CACHE, "Geoip Region with memory cache", 10000);
69 | $mainapp->testgeoipdatabase(GEOIP_CITY_DATABASE, GEOIP_STANDARD, "Geoip City ", 10000);
70 | $mainapp->testgeoipdatabase(GEOIP_CITY_DATABASE, GEOIP_MEMORY_CACHE, "Geoip City with memory cache", 10000);
71 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MaxMind GeoIP Legacy PHP API #
2 |
3 | ## Important Note ##
4 |
5 | This API is for the GeoIP Legacy format (dat). To read the MaxMind DB format
6 | (mmdb) used by GeoIP2, please see
7 | [our GeoIP2 PHP API](https://github.com/maxmind/GeoIP2-php).
8 |
9 | ## Requirements ##
10 |
11 | This module has no external dependencies. You only need a MaxMind GeoIP
12 | database. To download a free GeoLite Legacy Country database, please see
13 | our [GeoLite Legacy page](http://dev.maxmind.com/geoip/legacy/geolite).
14 |
15 | ## Install via Composer ##
16 |
17 | We recommend installing this package with [Composer](http://getcomposer.org/).
18 |
19 | ### Download Composer ###
20 |
21 | To download Composer, run in the root directory of your project:
22 |
23 | ```bash
24 | curl -sS https://getcomposer.org/installer | php
25 | ```
26 |
27 | You should now have the file `composer.phar` in your project directory.
28 |
29 | ### Install Dependencies ###
30 |
31 | Run in your project root:
32 |
33 | ```
34 | php composer.phar require geoip/geoip:~1.14
35 | ```
36 |
37 | You should now have the files `composer.json` and `composer.lock` as well as
38 | the directory `vendor` in your project directory. If you use a version control
39 | system, `composer.json` should be added to it.
40 |
41 | ### Require Autoloader ###
42 |
43 | After installing the dependencies, you need to require the Composer autoloader
44 | from your code:
45 |
46 | ```php
47 | require 'vendor/autoload.php';
48 | ```
49 |
50 | ## Install without Composer ##
51 |
52 | Place the 'geoip.inc' file in the `include_path` as specified in your
53 | `php.ini` file or place it in the same directory as your PHP scripts.
54 |
55 | ## Usage ##
56 |
57 | Gets country name by hostname :
58 |
59 | ```php
60 | = 4.0.4 compiled with `--enable-shmop`
80 | configure time. See (http://us2.php.net/manual/en/ref.shmop.php).
81 | In addition, you should call `geoip_load_shared_mem` before calling
82 | `geoip_open`. See `sample_city.php` for an example of shared memory caching.
83 |
84 | ## Support ##
85 |
86 | For help with this API or our databases, please see [our support page]
87 | (http://www.maxmind.com/en/support).
88 |
89 | ## Copyright and License ##
90 |
91 | This software is Copyright (c) 2014 by MaxMind, Inc.
92 |
93 | This is free software, licensed under the GNU Lesser General Public License
94 | version 2.1 or later.
95 |
96 | ## Thanks ##
97 |
98 | Thanks to Jim Winstead.
99 |
--------------------------------------------------------------------------------
/src/geoipcity.inc:
--------------------------------------------------------------------------------
1 | databaseSegments) {
48 | return null;
49 | }
50 | return _common_get_record($gi, $seek_country);
51 | }
52 |
53 | function _common_get_record($gi, $seek_country)
54 | {
55 | // workaround php's broken substr, strpos, etc handling with
56 | // mbstring.func_overload and mbstring.internal_encoding
57 | $mbExists = extension_loaded('mbstring');
58 | if ($mbExists) {
59 | $enc = mb_internal_encoding();
60 | mb_internal_encoding('ISO-8859-1');
61 | }
62 |
63 | $record_pointer = $seek_country + (2 * $gi->record_length - 1) * $gi->databaseSegments;
64 |
65 | if ($gi->flags & GEOIP_MEMORY_CACHE) {
66 | $record_buf = substr($gi->memory_buffer, $record_pointer, FULL_RECORD_LENGTH);
67 | } elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
68 | $record_buf = @shmop_read($gi->shmid, $record_pointer, FULL_RECORD_LENGTH);
69 | } else {
70 | fseek($gi->filehandle, $record_pointer, SEEK_SET);
71 | $record_buf = fread($gi->filehandle, FULL_RECORD_LENGTH);
72 | }
73 | $record = new geoiprecord;
74 | $record_buf_pos = 0;
75 | $char = ord(substr($record_buf, $record_buf_pos, 1));
76 | $record->country_code = $gi->GEOIP_COUNTRY_CODES[$char];
77 | $record->country_code3 = $gi->GEOIP_COUNTRY_CODES3[$char];
78 | $record->country_name = $gi->GEOIP_COUNTRY_NAMES[$char];
79 | $record->continent_code = $gi->GEOIP_CONTINENT_CODES[$char];
80 | $record_buf_pos++;
81 | $str_length = 0;
82 |
83 | // Get region
84 | $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
85 | while ($char != 0) {
86 | $str_length++;
87 | $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
88 | }
89 | if ($str_length > 0) {
90 | $record->region = substr($record_buf, $record_buf_pos, $str_length);
91 | }
92 | $record_buf_pos += $str_length + 1;
93 | $str_length = 0;
94 | // Get city
95 | $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
96 | while ($char != 0) {
97 | $str_length++;
98 | $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
99 | }
100 | if ($str_length > 0) {
101 | $record->city = substr($record_buf, $record_buf_pos, $str_length);
102 | }
103 | $record_buf_pos += $str_length + 1;
104 | $str_length = 0;
105 | // Get postal code
106 | $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
107 | while ($char != 0) {
108 | $str_length++;
109 | $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1));
110 | }
111 | if ($str_length > 0) {
112 | $record->postal_code = substr($record_buf, $record_buf_pos, $str_length);
113 | }
114 | $record_buf_pos += $str_length + 1;
115 | $str_length = 0;
116 | // Get latitude and longitude
117 | $latitude = 0;
118 | $longitude = 0;
119 | for ($j = 0; $j < 3; ++$j) {
120 | $char = ord(substr($record_buf, $record_buf_pos++, 1));
121 | $latitude += ($char << ($j * 8));
122 | }
123 | $record->latitude = ($latitude / 10000) - 180;
124 | for ($j = 0; $j < 3; ++$j) {
125 | $char = ord(substr($record_buf, $record_buf_pos++, 1));
126 | $longitude += ($char << ($j * 8));
127 | }
128 | $record->longitude = ($longitude / 10000) - 180;
129 | if (GEOIP_CITY_EDITION_REV1 == $gi->databaseType) {
130 | $metroarea_combo = 0;
131 | if ($record->country_code == "US") {
132 | for ($j = 0; $j < 3; ++$j) {
133 | $char = ord(substr($record_buf, $record_buf_pos++, 1));
134 | $metroarea_combo += ($char << ($j * 8));
135 | }
136 | $record->metro_code = $record->dma_code = floor($metroarea_combo / 1000);
137 | $record->area_code = $metroarea_combo % 1000;
138 | }
139 | }
140 | if ($mbExists) {
141 | mb_internal_encoding($enc);
142 | }
143 | return $record;
144 | }
145 |
146 | function GeoIP_record_by_addr_v6($gi, $addr)
147 | {
148 | if ($addr == null) {
149 | return 0;
150 | }
151 | $ipnum = inet_pton($addr);
152 | return _get_record_v6($gi, $ipnum);
153 | }
154 |
155 | function _get_record($gi, $ipnum)
156 | {
157 | $seek_country = _geoip_seek_country($gi, $ipnum);
158 | if ($seek_country == $gi->databaseSegments) {
159 | return null;
160 | }
161 | return _common_get_record($gi, $seek_country);
162 | }
163 |
164 | function GeoIP_record_by_addr($gi, $addr)
165 | {
166 | if ($addr == null) {
167 | return 0;
168 | }
169 | $ipnum = ip2long($addr);
170 | return _get_record($gi, $ipnum);
171 | }
172 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 2.1, February 1999
3 |
4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | [This is the first released version of the Lesser GPL. It also counts
10 | as the successor of the GNU Library Public License, version 2, hence
11 | the version number 2.1.]
12 |
13 | Preamble
14 |
15 | The licenses for most software are designed to take away your
16 | freedom to share and change it. By contrast, the GNU General Public
17 | Licenses are intended to guarantee your freedom to share and change
18 | free software--to make sure the software is free for all its users.
19 |
20 | This license, the Lesser General Public License, applies to some
21 | specially designated software packages--typically libraries--of the
22 | Free Software Foundation and other authors who decide to use it. You
23 | can use it too, but we suggest you first think carefully about whether
24 | this license or the ordinary General Public License is the better
25 | strategy to use in any particular case, based on the explanations below.
26 |
27 | When we speak of free software, we are referring to freedom of use,
28 | not price. Our General Public Licenses are designed to make sure that
29 | you have the freedom to distribute copies of free software (and charge
30 | for this service if you wish); that you receive source code or can get
31 | it if you want it; that you can change the software and use pieces of
32 | it in new free programs; and that you are informed that you can do
33 | these things.
34 |
35 | To protect your rights, we need to make restrictions that forbid
36 | distributors to deny you these rights or to ask you to surrender these
37 | rights. These restrictions translate to certain responsibilities for
38 | you if you distribute copies of the library or if you modify it.
39 |
40 | For example, if you distribute copies of the library, whether gratis
41 | or for a fee, you must give the recipients all the rights that we gave
42 | you. You must make sure that they, too, receive or can get the source
43 | code. If you link other code with the library, you must provide
44 | complete object files to the recipients, so that they can relink them
45 | with the library after making changes to the library and recompiling
46 | it. And you must show them these terms so they know their rights.
47 |
48 | We protect your rights with a two-step method: (1) we copyright the
49 | library, and (2) we offer you this license, which gives you legal
50 | permission to copy, distribute and/or modify the library.
51 |
52 | To protect each distributor, we want to make it very clear that
53 | there is no warranty for the free library. Also, if the library is
54 | modified by someone else and passed on, the recipients should know
55 | that what they have is not the original version, so that the original
56 | author's reputation will not be affected by problems that might be
57 | introduced by others.
58 |
59 | Finally, software patents pose a constant threat to the existence of
60 | any free program. We wish to make sure that a company cannot
61 | effectively restrict the users of a free program by obtaining a
62 | restrictive license from a patent holder. Therefore, we insist that
63 | any patent license obtained for a version of the library must be
64 | consistent with the full freedom of use specified in this license.
65 |
66 | Most GNU software, including some libraries, is covered by the
67 | ordinary GNU General Public License. This license, the GNU Lesser
68 | General Public License, applies to certain designated libraries, and
69 | is quite different from the ordinary General Public License. We use
70 | this license for certain libraries in order to permit linking those
71 | libraries into non-free programs.
72 |
73 | When a program is linked with a library, whether statically or using
74 | a shared library, the combination of the two is legally speaking a
75 | combined work, a derivative of the original library. The ordinary
76 | General Public License therefore permits such linking only if the
77 | entire combination fits its criteria of freedom. The Lesser General
78 | Public License permits more lax criteria for linking other code with
79 | the library.
80 |
81 | We call this license the "Lesser" General Public License because it
82 | does Less to protect the user's freedom than the ordinary General
83 | Public License. It also provides other free software developers Less
84 | of an advantage over competing non-free programs. These disadvantages
85 | are the reason we use the ordinary General Public License for many
86 | libraries. However, the Lesser license provides advantages in certain
87 | special circumstances.
88 |
89 | For example, on rare occasions, there may be a special need to
90 | encourage the widest possible use of a certain library, so that it becomes
91 | a de-facto standard. To achieve this, non-free programs must be
92 | allowed to use the library. A more frequent case is that a free
93 | library does the same job as widely used non-free libraries. In this
94 | case, there is little to gain by limiting the free library to free
95 | software only, so we use the Lesser General Public License.
96 |
97 | In other cases, permission to use a particular library in non-free
98 | programs enables a greater number of people to use a large body of
99 | free software. For example, permission to use the GNU C Library in
100 | non-free programs enables many more people to use the whole GNU
101 | operating system, as well as its variant, the GNU/Linux operating
102 | system.
103 |
104 | Although the Lesser General Public License is Less protective of the
105 | users' freedom, it does ensure that the user of a program that is
106 | linked with the Library has the freedom and the wherewithal to run
107 | that program using a modified version of the Library.
108 |
109 | The precise terms and conditions for copying, distribution and
110 | modification follow. Pay close attention to the difference between a
111 | "work based on the library" and a "work that uses the library". The
112 | former contains code derived from the library, whereas the latter must
113 | be combined with the library in order to run.
114 |
115 | GNU LESSER GENERAL PUBLIC LICENSE
116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117 |
118 | 0. This License Agreement applies to any software library or other
119 | program which contains a notice placed by the copyright holder or
120 | other authorized party saying it may be distributed under the terms of
121 | this Lesser General Public License (also called "this License").
122 | Each licensee is addressed as "you".
123 |
124 | A "library" means a collection of software functions and/or data
125 | prepared so as to be conveniently linked with application programs
126 | (which use some of those functions and data) to form executables.
127 |
128 | The "Library", below, refers to any such software library or work
129 | which has been distributed under these terms. A "work based on the
130 | Library" means either the Library or any derivative work under
131 | copyright law: that is to say, a work containing the Library or a
132 | portion of it, either verbatim or with modifications and/or translated
133 | straightforwardly into another language. (Hereinafter, translation is
134 | included without limitation in the term "modification".)
135 |
136 | "Source code" for a work means the preferred form of the work for
137 | making modifications to it. For a library, complete source code means
138 | all the source code for all modules it contains, plus any associated
139 | interface definition files, plus the scripts used to control compilation
140 | and installation of the library.
141 |
142 | Activities other than copying, distribution and modification are not
143 | covered by this License; they are outside its scope. The act of
144 | running a program using the Library is not restricted, and output from
145 | such a program is covered only if its contents constitute a work based
146 | on the Library (independent of the use of the Library in a tool for
147 | writing it). Whether that is true depends on what the Library does
148 | and what the program that uses the Library does.
149 |
150 | 1. You may copy and distribute verbatim copies of the Library's
151 | complete source code as you receive it, in any medium, provided that
152 | you conspicuously and appropriately publish on each copy an
153 | appropriate copyright notice and disclaimer of warranty; keep intact
154 | all the notices that refer to this License and to the absence of any
155 | warranty; and distribute a copy of this License along with the
156 | Library.
157 |
158 | You may charge a fee for the physical act of transferring a copy,
159 | and you may at your option offer warranty protection in exchange for a
160 | fee.
161 |
162 | 2. You may modify your copy or copies of the Library or any portion
163 | of it, thus forming a work based on the Library, and copy and
164 | distribute such modifications or work under the terms of Section 1
165 | above, provided that you also meet all of these conditions:
166 |
167 | a) The modified work must itself be a software library.
168 |
169 | b) You must cause the files modified to carry prominent notices
170 | stating that you changed the files and the date of any change.
171 |
172 | c) You must cause the whole of the work to be licensed at no
173 | charge to all third parties under the terms of this License.
174 |
175 | d) If a facility in the modified Library refers to a function or a
176 | table of data to be supplied by an application program that uses
177 | the facility, other than as an argument passed when the facility
178 | is invoked, then you must make a good faith effort to ensure that,
179 | in the event an application does not supply such function or
180 | table, the facility still operates, and performs whatever part of
181 | its purpose remains meaningful.
182 |
183 | (For example, a function in a library to compute square roots has
184 | a purpose that is entirely well-defined independent of the
185 | application. Therefore, Subsection 2d requires that any
186 | application-supplied function or table used by this function must
187 | be optional: if the application does not supply it, the square
188 | root function must still compute square roots.)
189 |
190 | These requirements apply to the modified work as a whole. If
191 | identifiable sections of that work are not derived from the Library,
192 | and can be reasonably considered independent and separate works in
193 | themselves, then this License, and its terms, do not apply to those
194 | sections when you distribute them as separate works. But when you
195 | distribute the same sections as part of a whole which is a work based
196 | on the Library, the distribution of the whole must be on the terms of
197 | this License, whose permissions for other licensees extend to the
198 | entire whole, and thus to each and every part regardless of who wrote
199 | it.
200 |
201 | Thus, it is not the intent of this section to claim rights or contest
202 | your rights to work written entirely by you; rather, the intent is to
203 | exercise the right to control the distribution of derivative or
204 | collective works based on the Library.
205 |
206 | In addition, mere aggregation of another work not based on the Library
207 | with the Library (or with a work based on the Library) on a volume of
208 | a storage or distribution medium does not bring the other work under
209 | the scope of this License.
210 |
211 | 3. You may opt to apply the terms of the ordinary GNU General Public
212 | License instead of this License to a given copy of the Library. To do
213 | this, you must alter all the notices that refer to this License, so
214 | that they refer to the ordinary GNU General Public License, version 2,
215 | instead of to this License. (If a newer version than version 2 of the
216 | ordinary GNU General Public License has appeared, then you can specify
217 | that version instead if you wish.) Do not make any other change in
218 | these notices.
219 |
220 | Once this change is made in a given copy, it is irreversible for
221 | that copy, so the ordinary GNU General Public License applies to all
222 | subsequent copies and derivative works made from that copy.
223 |
224 | This option is useful when you wish to copy part of the code of
225 | the Library into a program that is not a library.
226 |
227 | 4. You may copy and distribute the Library (or a portion or
228 | derivative of it, under Section 2) in object code or executable form
229 | under the terms of Sections 1 and 2 above provided that you accompany
230 | it with the complete corresponding machine-readable source code, which
231 | must be distributed under the terms of Sections 1 and 2 above on a
232 | medium customarily used for software interchange.
233 |
234 | If distribution of object code is made by offering access to copy
235 | from a designated place, then offering equivalent access to copy the
236 | source code from the same place satisfies the requirement to
237 | distribute the source code, even though third parties are not
238 | compelled to copy the source along with the object code.
239 |
240 | 5. A program that contains no derivative of any portion of the
241 | Library, but is designed to work with the Library by being compiled or
242 | linked with it, is called a "work that uses the Library". Such a
243 | work, in isolation, is not a derivative work of the Library, and
244 | therefore falls outside the scope of this License.
245 |
246 | However, linking a "work that uses the Library" with the Library
247 | creates an executable that is a derivative of the Library (because it
248 | contains portions of the Library), rather than a "work that uses the
249 | library". The executable is therefore covered by this License.
250 | Section 6 states terms for distribution of such executables.
251 |
252 | When a "work that uses the Library" uses material from a header file
253 | that is part of the Library, the object code for the work may be a
254 | derivative work of the Library even though the source code is not.
255 | Whether this is true is especially significant if the work can be
256 | linked without the Library, or if the work is itself a library. The
257 | threshold for this to be true is not precisely defined by law.
258 |
259 | If such an object file uses only numerical parameters, data
260 | structure layouts and accessors, and small macros and small inline
261 | functions (ten lines or less in length), then the use of the object
262 | file is unrestricted, regardless of whether it is legally a derivative
263 | work. (Executables containing this object code plus portions of the
264 | Library will still fall under Section 6.)
265 |
266 | Otherwise, if the work is a derivative of the Library, you may
267 | distribute the object code for the work under the terms of Section 6.
268 | Any executables containing that work also fall under Section 6,
269 | whether or not they are linked directly with the Library itself.
270 |
271 | 6. As an exception to the Sections above, you may also combine or
272 | link a "work that uses the Library" with the Library to produce a
273 | work containing portions of the Library, and distribute that work
274 | under terms of your choice, provided that the terms permit
275 | modification of the work for the customer's own use and reverse
276 | engineering for debugging such modifications.
277 |
278 | You must give prominent notice with each copy of the work that the
279 | Library is used in it and that the Library and its use are covered by
280 | this License. You must supply a copy of this License. If the work
281 | during execution displays copyright notices, you must include the
282 | copyright notice for the Library among them, as well as a reference
283 | directing the user to the copy of this License. Also, you must do one
284 | of these things:
285 |
286 | a) Accompany the work with the complete corresponding
287 | machine-readable source code for the Library including whatever
288 | changes were used in the work (which must be distributed under
289 | Sections 1 and 2 above); and, if the work is an executable linked
290 | with the Library, with the complete machine-readable "work that
291 | uses the Library", as object code and/or source code, so that the
292 | user can modify the Library and then relink to produce a modified
293 | executable containing the modified Library. (It is understood
294 | that the user who changes the contents of definitions files in the
295 | Library will not necessarily be able to recompile the application
296 | to use the modified definitions.)
297 |
298 | b) Use a suitable shared library mechanism for linking with the
299 | Library. A suitable mechanism is one that (1) uses at run time a
300 | copy of the library already present on the user's computer system,
301 | rather than copying library functions into the executable, and (2)
302 | will operate properly with a modified version of the library, if
303 | the user installs one, as long as the modified version is
304 | interface-compatible with the version that the work was made with.
305 |
306 | c) Accompany the work with a written offer, valid for at
307 | least three years, to give the same user the materials
308 | specified in Subsection 6a, above, for a charge no more
309 | than the cost of performing this distribution.
310 |
311 | d) If distribution of the work is made by offering access to copy
312 | from a designated place, offer equivalent access to copy the above
313 | specified materials from the same place.
314 |
315 | e) Verify that the user has already received a copy of these
316 | materials or that you have already sent this user a copy.
317 |
318 | For an executable, the required form of the "work that uses the
319 | Library" must include any data and utility programs needed for
320 | reproducing the executable from it. However, as a special exception,
321 | the materials to be distributed need not include anything that is
322 | normally distributed (in either source or binary form) with the major
323 | components (compiler, kernel, and so on) of the operating system on
324 | which the executable runs, unless that component itself accompanies
325 | the executable.
326 |
327 | It may happen that this requirement contradicts the license
328 | restrictions of other proprietary libraries that do not normally
329 | accompany the operating system. Such a contradiction means you cannot
330 | use both them and the Library together in an executable that you
331 | distribute.
332 |
333 | 7. You may place library facilities that are a work based on the
334 | Library side-by-side in a single library together with other library
335 | facilities not covered by this License, and distribute such a combined
336 | library, provided that the separate distribution of the work based on
337 | the Library and of the other library facilities is otherwise
338 | permitted, and provided that you do these two things:
339 |
340 | a) Accompany the combined library with a copy of the same work
341 | based on the Library, uncombined with any other library
342 | facilities. This must be distributed under the terms of the
343 | Sections above.
344 |
345 | b) Give prominent notice with the combined library of the fact
346 | that part of it is a work based on the Library, and explaining
347 | where to find the accompanying uncombined form of the same work.
348 |
349 | 8. You may not copy, modify, sublicense, link with, or distribute
350 | the Library except as expressly provided under this License. Any
351 | attempt otherwise to copy, modify, sublicense, link with, or
352 | distribute the Library is void, and will automatically terminate your
353 | rights under this License. However, parties who have received copies,
354 | or rights, from you under this License will not have their licenses
355 | terminated so long as such parties remain in full compliance.
356 |
357 | 9. You are not required to accept this License, since you have not
358 | signed it. However, nothing else grants you permission to modify or
359 | distribute the Library or its derivative works. These actions are
360 | prohibited by law if you do not accept this License. Therefore, by
361 | modifying or distributing the Library (or any work based on the
362 | Library), you indicate your acceptance of this License to do so, and
363 | all its terms and conditions for copying, distributing or modifying
364 | the Library or works based on it.
365 |
366 | 10. Each time you redistribute the Library (or any work based on the
367 | Library), the recipient automatically receives a license from the
368 | original licensor to copy, distribute, link with or modify the Library
369 | subject to these terms and conditions. You may not impose any further
370 | restrictions on the recipients' exercise of the rights granted herein.
371 | You are not responsible for enforcing compliance by third parties with
372 | this License.
373 |
374 | 11. If, as a consequence of a court judgment or allegation of patent
375 | infringement or for any other reason (not limited to patent issues),
376 | conditions are imposed on you (whether by court order, agreement or
377 | otherwise) that contradict the conditions of this License, they do not
378 | excuse you from the conditions of this License. If you cannot
379 | distribute so as to satisfy simultaneously your obligations under this
380 | License and any other pertinent obligations, then as a consequence you
381 | may not distribute the Library at all. For example, if a patent
382 | license would not permit royalty-free redistribution of the Library by
383 | all those who receive copies directly or indirectly through you, then
384 | the only way you could satisfy both it and this License would be to
385 | refrain entirely from distribution of the Library.
386 |
387 | If any portion of this section is held invalid or unenforceable under any
388 | particular circumstance, the balance of the section is intended to apply,
389 | and the section as a whole is intended to apply in other circumstances.
390 |
391 | It is not the purpose of this section to induce you to infringe any
392 | patents or other property right claims or to contest validity of any
393 | such claims; this section has the sole purpose of protecting the
394 | integrity of the free software distribution system which is
395 | implemented by public license practices. Many people have made
396 | generous contributions to the wide range of software distributed
397 | through that system in reliance on consistent application of that
398 | system; it is up to the author/donor to decide if he or she is willing
399 | to distribute software through any other system and a licensee cannot
400 | impose that choice.
401 |
402 | This section is intended to make thoroughly clear what is believed to
403 | be a consequence of the rest of this License.
404 |
405 | 12. If the distribution and/or use of the Library is restricted in
406 | certain countries either by patents or by copyrighted interfaces, the
407 | original copyright holder who places the Library under this License may add
408 | an explicit geographical distribution limitation excluding those countries,
409 | so that distribution is permitted only in or among countries not thus
410 | excluded. In such case, this License incorporates the limitation as if
411 | written in the body of this License.
412 |
413 | 13. The Free Software Foundation may publish revised and/or new
414 | versions of the Lesser General Public License from time to time.
415 | Such new versions will be similar in spirit to the present version,
416 | but may differ in detail to address new problems or concerns.
417 |
418 | Each version is given a distinguishing version number. If the Library
419 | specifies a version number of this License which applies to it and
420 | "any later version", you have the option of following the terms and
421 | conditions either of that version or of any later version published by
422 | the Free Software Foundation. If the Library does not specify a
423 | license version number, you may choose any version ever published by
424 | the Free Software Foundation.
425 |
426 | 14. If you wish to incorporate parts of the Library into other free
427 | programs whose distribution conditions are incompatible with these,
428 | write to the author to ask for permission. For software which is
429 | copyrighted by the Free Software Foundation, write to the Free
430 | Software Foundation; we sometimes make exceptions for this. Our
431 | decision will be guided by the two goals of preserving the free status
432 | of all derivatives of our free software and of promoting the sharing
433 | and reuse of software generally.
434 |
435 | NO WARRANTY
436 |
437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446 |
447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456 | DAMAGES.
457 |
458 | END OF TERMS AND CONDITIONS
459 |
460 | How to Apply These Terms to Your New Libraries
461 |
462 | If you develop a new library, and you want it to be of the greatest
463 | possible use to the public, we recommend making it free software that
464 | everyone can redistribute and change. You can do so by permitting
465 | redistribution under these terms (or, alternatively, under the terms of the
466 | ordinary General Public License).
467 |
468 | To apply these terms, attach the following notices to the library. It is
469 | safest to attach them to the start of each source file to most effectively
470 | convey the exclusion of warranty; and each file should have at least the
471 | "copyright" line and a pointer to where the full notice is found.
472 |
473 |
474 | Copyright (C)
475 |
476 | This library is free software; you can redistribute it and/or
477 | modify it under the terms of the GNU Lesser General Public
478 | License as published by the Free Software Foundation; either
479 | version 2.1 of the License, or (at your option) any later version.
480 |
481 | This library is distributed in the hope that it will be useful,
482 | but WITHOUT ANY WARRANTY; without even the implied warranty of
483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
484 | Lesser General Public License for more details.
485 |
486 | You should have received a copy of the GNU Lesser General Public
487 | License along with this library; if not, write to the Free Software
488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
489 |
490 | Also add information on how to contact you by electronic and paper mail.
491 |
492 | You should also get your employer (if you work as a programmer) or your
493 | school, if any, to sign a "copyright disclaimer" for the library, if
494 | necessary. Here is a sample; alter the names:
495 |
496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the
497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker.
498 |
499 | , 1 April 1990
500 | Ty Coon, President of Vice
501 |
502 | That's all there is to it!
503 |
--------------------------------------------------------------------------------
/src/geoip.inc:
--------------------------------------------------------------------------------
1 | 0,
84 | "AP" => 1,
85 | "EU" => 2,
86 | "AD" => 3,
87 | "AE" => 4,
88 | "AF" => 5,
89 | "AG" => 6,
90 | "AI" => 7,
91 | "AL" => 8,
92 | "AM" => 9,
93 | "CW" => 10,
94 | "AO" => 11,
95 | "AQ" => 12,
96 | "AR" => 13,
97 | "AS" => 14,
98 | "AT" => 15,
99 | "AU" => 16,
100 | "AW" => 17,
101 | "AZ" => 18,
102 | "BA" => 19,
103 | "BB" => 20,
104 | "BD" => 21,
105 | "BE" => 22,
106 | "BF" => 23,
107 | "BG" => 24,
108 | "BH" => 25,
109 | "BI" => 26,
110 | "BJ" => 27,
111 | "BM" => 28,
112 | "BN" => 29,
113 | "BO" => 30,
114 | "BR" => 31,
115 | "BS" => 32,
116 | "BT" => 33,
117 | "BV" => 34,
118 | "BW" => 35,
119 | "BY" => 36,
120 | "BZ" => 37,
121 | "CA" => 38,
122 | "CC" => 39,
123 | "CD" => 40,
124 | "CF" => 41,
125 | "CG" => 42,
126 | "CH" => 43,
127 | "CI" => 44,
128 | "CK" => 45,
129 | "CL" => 46,
130 | "CM" => 47,
131 | "CN" => 48,
132 | "CO" => 49,
133 | "CR" => 50,
134 | "CU" => 51,
135 | "CV" => 52,
136 | "CX" => 53,
137 | "CY" => 54,
138 | "CZ" => 55,
139 | "DE" => 56,
140 | "DJ" => 57,
141 | "DK" => 58,
142 | "DM" => 59,
143 | "DO" => 60,
144 | "DZ" => 61,
145 | "EC" => 62,
146 | "EE" => 63,
147 | "EG" => 64,
148 | "EH" => 65,
149 | "ER" => 66,
150 | "ES" => 67,
151 | "ET" => 68,
152 | "FI" => 69,
153 | "FJ" => 70,
154 | "FK" => 71,
155 | "FM" => 72,
156 | "FO" => 73,
157 | "FR" => 74,
158 | "SX" => 75,
159 | "GA" => 76,
160 | "GB" => 77,
161 | "GD" => 78,
162 | "GE" => 79,
163 | "GF" => 80,
164 | "GH" => 81,
165 | "GI" => 82,
166 | "GL" => 83,
167 | "GM" => 84,
168 | "GN" => 85,
169 | "GP" => 86,
170 | "GQ" => 87,
171 | "GR" => 88,
172 | "GS" => 89,
173 | "GT" => 90,
174 | "GU" => 91,
175 | "GW" => 92,
176 | "GY" => 93,
177 | "HK" => 94,
178 | "HM" => 95,
179 | "HN" => 96,
180 | "HR" => 97,
181 | "HT" => 98,
182 | "HU" => 99,
183 | "ID" => 100,
184 | "IE" => 101,
185 | "IL" => 102,
186 | "IN" => 103,
187 | "IO" => 104,
188 | "IQ" => 105,
189 | "IR" => 106,
190 | "IS" => 107,
191 | "IT" => 108,
192 | "JM" => 109,
193 | "JO" => 110,
194 | "JP" => 111,
195 | "KE" => 112,
196 | "KG" => 113,
197 | "KH" => 114,
198 | "KI" => 115,
199 | "KM" => 116,
200 | "KN" => 117,
201 | "KP" => 118,
202 | "KR" => 119,
203 | "KW" => 120,
204 | "KY" => 121,
205 | "KZ" => 122,
206 | "LA" => 123,
207 | "LB" => 124,
208 | "LC" => 125,
209 | "LI" => 126,
210 | "LK" => 127,
211 | "LR" => 128,
212 | "LS" => 129,
213 | "LT" => 130,
214 | "LU" => 131,
215 | "LV" => 132,
216 | "LY" => 133,
217 | "MA" => 134,
218 | "MC" => 135,
219 | "MD" => 136,
220 | "MG" => 137,
221 | "MH" => 138,
222 | "MK" => 139,
223 | "ML" => 140,
224 | "MM" => 141,
225 | "MN" => 142,
226 | "MO" => 143,
227 | "MP" => 144,
228 | "MQ" => 145,
229 | "MR" => 146,
230 | "MS" => 147,
231 | "MT" => 148,
232 | "MU" => 149,
233 | "MV" => 150,
234 | "MW" => 151,
235 | "MX" => 152,
236 | "MY" => 153,
237 | "MZ" => 154,
238 | "NA" => 155,
239 | "NC" => 156,
240 | "NE" => 157,
241 | "NF" => 158,
242 | "NG" => 159,
243 | "NI" => 160,
244 | "NL" => 161,
245 | "NO" => 162,
246 | "NP" => 163,
247 | "NR" => 164,
248 | "NU" => 165,
249 | "NZ" => 166,
250 | "OM" => 167,
251 | "PA" => 168,
252 | "PE" => 169,
253 | "PF" => 170,
254 | "PG" => 171,
255 | "PH" => 172,
256 | "PK" => 173,
257 | "PL" => 174,
258 | "PM" => 175,
259 | "PN" => 176,
260 | "PR" => 177,
261 | "PS" => 178,
262 | "PT" => 179,
263 | "PW" => 180,
264 | "PY" => 181,
265 | "QA" => 182,
266 | "RE" => 183,
267 | "RO" => 184,
268 | "RU" => 185,
269 | "RW" => 186,
270 | "SA" => 187,
271 | "SB" => 188,
272 | "SC" => 189,
273 | "SD" => 190,
274 | "SE" => 191,
275 | "SG" => 192,
276 | "SH" => 193,
277 | "SI" => 194,
278 | "SJ" => 195,
279 | "SK" => 196,
280 | "SL" => 197,
281 | "SM" => 198,
282 | "SN" => 199,
283 | "SO" => 200,
284 | "SR" => 201,
285 | "ST" => 202,
286 | "SV" => 203,
287 | "SY" => 204,
288 | "SZ" => 205,
289 | "TC" => 206,
290 | "TD" => 207,
291 | "TF" => 208,
292 | "TG" => 209,
293 | "TH" => 210,
294 | "TJ" => 211,
295 | "TK" => 212,
296 | "TM" => 213,
297 | "TN" => 214,
298 | "TO" => 215,
299 | "TL" => 216,
300 | "TR" => 217,
301 | "TT" => 218,
302 | "TV" => 219,
303 | "TW" => 220,
304 | "TZ" => 221,
305 | "UA" => 222,
306 | "UG" => 223,
307 | "UM" => 224,
308 | "US" => 225,
309 | "UY" => 226,
310 | "UZ" => 227,
311 | "VA" => 228,
312 | "VC" => 229,
313 | "VE" => 230,
314 | "VG" => 231,
315 | "VI" => 232,
316 | "VN" => 233,
317 | "VU" => 234,
318 | "WF" => 235,
319 | "WS" => 236,
320 | "YE" => 237,
321 | "YT" => 238,
322 | "RS" => 239,
323 | "ZA" => 240,
324 | "ZM" => 241,
325 | "ME" => 242,
326 | "ZW" => 243,
327 | "A1" => 244,
328 | "A2" => 245,
329 | "O1" => 246,
330 | "AX" => 247,
331 | "GG" => 248,
332 | "IM" => 249,
333 | "JE" => 250,
334 | "BL" => 251,
335 | "MF" => 252,
336 | "BQ" => 253,
337 | "SS" => 254
338 | );
339 |
340 | public $GEOIP_COUNTRY_CODES = array(
341 | "",
342 | "AP",
343 | "EU",
344 | "AD",
345 | "AE",
346 | "AF",
347 | "AG",
348 | "AI",
349 | "AL",
350 | "AM",
351 | "CW",
352 | "AO",
353 | "AQ",
354 | "AR",
355 | "AS",
356 | "AT",
357 | "AU",
358 | "AW",
359 | "AZ",
360 | "BA",
361 | "BB",
362 | "BD",
363 | "BE",
364 | "BF",
365 | "BG",
366 | "BH",
367 | "BI",
368 | "BJ",
369 | "BM",
370 | "BN",
371 | "BO",
372 | "BR",
373 | "BS",
374 | "BT",
375 | "BV",
376 | "BW",
377 | "BY",
378 | "BZ",
379 | "CA",
380 | "CC",
381 | "CD",
382 | "CF",
383 | "CG",
384 | "CH",
385 | "CI",
386 | "CK",
387 | "CL",
388 | "CM",
389 | "CN",
390 | "CO",
391 | "CR",
392 | "CU",
393 | "CV",
394 | "CX",
395 | "CY",
396 | "CZ",
397 | "DE",
398 | "DJ",
399 | "DK",
400 | "DM",
401 | "DO",
402 | "DZ",
403 | "EC",
404 | "EE",
405 | "EG",
406 | "EH",
407 | "ER",
408 | "ES",
409 | "ET",
410 | "FI",
411 | "FJ",
412 | "FK",
413 | "FM",
414 | "FO",
415 | "FR",
416 | "SX",
417 | "GA",
418 | "GB",
419 | "GD",
420 | "GE",
421 | "GF",
422 | "GH",
423 | "GI",
424 | "GL",
425 | "GM",
426 | "GN",
427 | "GP",
428 | "GQ",
429 | "GR",
430 | "GS",
431 | "GT",
432 | "GU",
433 | "GW",
434 | "GY",
435 | "HK",
436 | "HM",
437 | "HN",
438 | "HR",
439 | "HT",
440 | "HU",
441 | "ID",
442 | "IE",
443 | "IL",
444 | "IN",
445 | "IO",
446 | "IQ",
447 | "IR",
448 | "IS",
449 | "IT",
450 | "JM",
451 | "JO",
452 | "JP",
453 | "KE",
454 | "KG",
455 | "KH",
456 | "KI",
457 | "KM",
458 | "KN",
459 | "KP",
460 | "KR",
461 | "KW",
462 | "KY",
463 | "KZ",
464 | "LA",
465 | "LB",
466 | "LC",
467 | "LI",
468 | "LK",
469 | "LR",
470 | "LS",
471 | "LT",
472 | "LU",
473 | "LV",
474 | "LY",
475 | "MA",
476 | "MC",
477 | "MD",
478 | "MG",
479 | "MH",
480 | "MK",
481 | "ML",
482 | "MM",
483 | "MN",
484 | "MO",
485 | "MP",
486 | "MQ",
487 | "MR",
488 | "MS",
489 | "MT",
490 | "MU",
491 | "MV",
492 | "MW",
493 | "MX",
494 | "MY",
495 | "MZ",
496 | "NA",
497 | "NC",
498 | "NE",
499 | "NF",
500 | "NG",
501 | "NI",
502 | "NL",
503 | "NO",
504 | "NP",
505 | "NR",
506 | "NU",
507 | "NZ",
508 | "OM",
509 | "PA",
510 | "PE",
511 | "PF",
512 | "PG",
513 | "PH",
514 | "PK",
515 | "PL",
516 | "PM",
517 | "PN",
518 | "PR",
519 | "PS",
520 | "PT",
521 | "PW",
522 | "PY",
523 | "QA",
524 | "RE",
525 | "RO",
526 | "RU",
527 | "RW",
528 | "SA",
529 | "SB",
530 | "SC",
531 | "SD",
532 | "SE",
533 | "SG",
534 | "SH",
535 | "SI",
536 | "SJ",
537 | "SK",
538 | "SL",
539 | "SM",
540 | "SN",
541 | "SO",
542 | "SR",
543 | "ST",
544 | "SV",
545 | "SY",
546 | "SZ",
547 | "TC",
548 | "TD",
549 | "TF",
550 | "TG",
551 | "TH",
552 | "TJ",
553 | "TK",
554 | "TM",
555 | "TN",
556 | "TO",
557 | "TL",
558 | "TR",
559 | "TT",
560 | "TV",
561 | "TW",
562 | "TZ",
563 | "UA",
564 | "UG",
565 | "UM",
566 | "US",
567 | "UY",
568 | "UZ",
569 | "VA",
570 | "VC",
571 | "VE",
572 | "VG",
573 | "VI",
574 | "VN",
575 | "VU",
576 | "WF",
577 | "WS",
578 | "YE",
579 | "YT",
580 | "RS",
581 | "ZA",
582 | "ZM",
583 | "ME",
584 | "ZW",
585 | "A1",
586 | "A2",
587 | "O1",
588 | "AX",
589 | "GG",
590 | "IM",
591 | "JE",
592 | "BL",
593 | "MF",
594 | "BQ",
595 | "SS",
596 | "O1"
597 | );
598 |
599 | public $GEOIP_COUNTRY_CODES3 = array(
600 | "",
601 | "AP",
602 | "EU",
603 | "AND",
604 | "ARE",
605 | "AFG",
606 | "ATG",
607 | "AIA",
608 | "ALB",
609 | "ARM",
610 | "CUW",
611 | "AGO",
612 | "ATA",
613 | "ARG",
614 | "ASM",
615 | "AUT",
616 | "AUS",
617 | "ABW",
618 | "AZE",
619 | "BIH",
620 | "BRB",
621 | "BGD",
622 | "BEL",
623 | "BFA",
624 | "BGR",
625 | "BHR",
626 | "BDI",
627 | "BEN",
628 | "BMU",
629 | "BRN",
630 | "BOL",
631 | "BRA",
632 | "BHS",
633 | "BTN",
634 | "BVT",
635 | "BWA",
636 | "BLR",
637 | "BLZ",
638 | "CAN",
639 | "CCK",
640 | "COD",
641 | "CAF",
642 | "COG",
643 | "CHE",
644 | "CIV",
645 | "COK",
646 | "CHL",
647 | "CMR",
648 | "CHN",
649 | "COL",
650 | "CRI",
651 | "CUB",
652 | "CPV",
653 | "CXR",
654 | "CYP",
655 | "CZE",
656 | "DEU",
657 | "DJI",
658 | "DNK",
659 | "DMA",
660 | "DOM",
661 | "DZA",
662 | "ECU",
663 | "EST",
664 | "EGY",
665 | "ESH",
666 | "ERI",
667 | "ESP",
668 | "ETH",
669 | "FIN",
670 | "FJI",
671 | "FLK",
672 | "FSM",
673 | "FRO",
674 | "FRA",
675 | "SXM",
676 | "GAB",
677 | "GBR",
678 | "GRD",
679 | "GEO",
680 | "GUF",
681 | "GHA",
682 | "GIB",
683 | "GRL",
684 | "GMB",
685 | "GIN",
686 | "GLP",
687 | "GNQ",
688 | "GRC",
689 | "SGS",
690 | "GTM",
691 | "GUM",
692 | "GNB",
693 | "GUY",
694 | "HKG",
695 | "HMD",
696 | "HND",
697 | "HRV",
698 | "HTI",
699 | "HUN",
700 | "IDN",
701 | "IRL",
702 | "ISR",
703 | "IND",
704 | "IOT",
705 | "IRQ",
706 | "IRN",
707 | "ISL",
708 | "ITA",
709 | "JAM",
710 | "JOR",
711 | "JPN",
712 | "KEN",
713 | "KGZ",
714 | "KHM",
715 | "KIR",
716 | "COM",
717 | "KNA",
718 | "PRK",
719 | "KOR",
720 | "KWT",
721 | "CYM",
722 | "KAZ",
723 | "LAO",
724 | "LBN",
725 | "LCA",
726 | "LIE",
727 | "LKA",
728 | "LBR",
729 | "LSO",
730 | "LTU",
731 | "LUX",
732 | "LVA",
733 | "LBY",
734 | "MAR",
735 | "MCO",
736 | "MDA",
737 | "MDG",
738 | "MHL",
739 | "MKD",
740 | "MLI",
741 | "MMR",
742 | "MNG",
743 | "MAC",
744 | "MNP",
745 | "MTQ",
746 | "MRT",
747 | "MSR",
748 | "MLT",
749 | "MUS",
750 | "MDV",
751 | "MWI",
752 | "MEX",
753 | "MYS",
754 | "MOZ",
755 | "NAM",
756 | "NCL",
757 | "NER",
758 | "NFK",
759 | "NGA",
760 | "NIC",
761 | "NLD",
762 | "NOR",
763 | "NPL",
764 | "NRU",
765 | "NIU",
766 | "NZL",
767 | "OMN",
768 | "PAN",
769 | "PER",
770 | "PYF",
771 | "PNG",
772 | "PHL",
773 | "PAK",
774 | "POL",
775 | "SPM",
776 | "PCN",
777 | "PRI",
778 | "PSE",
779 | "PRT",
780 | "PLW",
781 | "PRY",
782 | "QAT",
783 | "REU",
784 | "ROU",
785 | "RUS",
786 | "RWA",
787 | "SAU",
788 | "SLB",
789 | "SYC",
790 | "SDN",
791 | "SWE",
792 | "SGP",
793 | "SHN",
794 | "SVN",
795 | "SJM",
796 | "SVK",
797 | "SLE",
798 | "SMR",
799 | "SEN",
800 | "SOM",
801 | "SUR",
802 | "STP",
803 | "SLV",
804 | "SYR",
805 | "SWZ",
806 | "TCA",
807 | "TCD",
808 | "ATF",
809 | "TGO",
810 | "THA",
811 | "TJK",
812 | "TKL",
813 | "TKM",
814 | "TUN",
815 | "TON",
816 | "TLS",
817 | "TUR",
818 | "TTO",
819 | "TUV",
820 | "TWN",
821 | "TZA",
822 | "UKR",
823 | "UGA",
824 | "UMI",
825 | "USA",
826 | "URY",
827 | "UZB",
828 | "VAT",
829 | "VCT",
830 | "VEN",
831 | "VGB",
832 | "VIR",
833 | "VNM",
834 | "VUT",
835 | "WLF",
836 | "WSM",
837 | "YEM",
838 | "MYT",
839 | "SRB",
840 | "ZAF",
841 | "ZMB",
842 | "MNE",
843 | "ZWE",
844 | "A1",
845 | "A2",
846 | "O1",
847 | "ALA",
848 | "GGY",
849 | "IMN",
850 | "JEY",
851 | "BLM",
852 | "MAF",
853 | "BES",
854 | "SSD",
855 | "O1"
856 | );
857 |
858 | public $GEOIP_COUNTRY_NAMES = array(
859 | "",
860 | "Asia/Pacific Region",
861 | "Europe",
862 | "Andorra",
863 | "United Arab Emirates",
864 | "Afghanistan",
865 | "Antigua and Barbuda",
866 | "Anguilla",
867 | "Albania",
868 | "Armenia",
869 | "Curacao",
870 | "Angola",
871 | "Antarctica",
872 | "Argentina",
873 | "American Samoa",
874 | "Austria",
875 | "Australia",
876 | "Aruba",
877 | "Azerbaijan",
878 | "Bosnia and Herzegovina",
879 | "Barbados",
880 | "Bangladesh",
881 | "Belgium",
882 | "Burkina Faso",
883 | "Bulgaria",
884 | "Bahrain",
885 | "Burundi",
886 | "Benin",
887 | "Bermuda",
888 | "Brunei Darussalam",
889 | "Bolivia",
890 | "Brazil",
891 | "Bahamas",
892 | "Bhutan",
893 | "Bouvet Island",
894 | "Botswana",
895 | "Belarus",
896 | "Belize",
897 | "Canada",
898 | "Cocos (Keeling) Islands",
899 | "Congo, The Democratic Republic of the",
900 | "Central African Republic",
901 | "Congo",
902 | "Switzerland",
903 | "Cote D'Ivoire",
904 | "Cook Islands",
905 | "Chile",
906 | "Cameroon",
907 | "China",
908 | "Colombia",
909 | "Costa Rica",
910 | "Cuba",
911 | "Cape Verde",
912 | "Christmas Island",
913 | "Cyprus",
914 | "Czech Republic",
915 | "Germany",
916 | "Djibouti",
917 | "Denmark",
918 | "Dominica",
919 | "Dominican Republic",
920 | "Algeria",
921 | "Ecuador",
922 | "Estonia",
923 | "Egypt",
924 | "Western Sahara",
925 | "Eritrea",
926 | "Spain",
927 | "Ethiopia",
928 | "Finland",
929 | "Fiji",
930 | "Falkland Islands (Malvinas)",
931 | "Micronesia, Federated States of",
932 | "Faroe Islands",
933 | "France",
934 | "Sint Maarten (Dutch part)",
935 | "Gabon",
936 | "United Kingdom",
937 | "Grenada",
938 | "Georgia",
939 | "French Guiana",
940 | "Ghana",
941 | "Gibraltar",
942 | "Greenland",
943 | "Gambia",
944 | "Guinea",
945 | "Guadeloupe",
946 | "Equatorial Guinea",
947 | "Greece",
948 | "South Georgia and the South Sandwich Islands",
949 | "Guatemala",
950 | "Guam",
951 | "Guinea-Bissau",
952 | "Guyana",
953 | "Hong Kong",
954 | "Heard Island and McDonald Islands",
955 | "Honduras",
956 | "Croatia",
957 | "Haiti",
958 | "Hungary",
959 | "Indonesia",
960 | "Ireland",
961 | "Israel",
962 | "India",
963 | "British Indian Ocean Territory",
964 | "Iraq",
965 | "Iran, Islamic Republic of",
966 | "Iceland",
967 | "Italy",
968 | "Jamaica",
969 | "Jordan",
970 | "Japan",
971 | "Kenya",
972 | "Kyrgyzstan",
973 | "Cambodia",
974 | "Kiribati",
975 | "Comoros",
976 | "Saint Kitts and Nevis",
977 | "Korea, Democratic People's Republic of",
978 | "Korea, Republic of",
979 | "Kuwait",
980 | "Cayman Islands",
981 | "Kazakhstan",
982 | "Lao People's Democratic Republic",
983 | "Lebanon",
984 | "Saint Lucia",
985 | "Liechtenstein",
986 | "Sri Lanka",
987 | "Liberia",
988 | "Lesotho",
989 | "Lithuania",
990 | "Luxembourg",
991 | "Latvia",
992 | "Libya",
993 | "Morocco",
994 | "Monaco",
995 | "Moldova, Republic of",
996 | "Madagascar",
997 | "Marshall Islands",
998 | "Macedonia",
999 | "Mali",
1000 | "Myanmar",
1001 | "Mongolia",
1002 | "Macau",
1003 | "Northern Mariana Islands",
1004 | "Martinique",
1005 | "Mauritania",
1006 | "Montserrat",
1007 | "Malta",
1008 | "Mauritius",
1009 | "Maldives",
1010 | "Malawi",
1011 | "Mexico",
1012 | "Malaysia",
1013 | "Mozambique",
1014 | "Namibia",
1015 | "New Caledonia",
1016 | "Niger",
1017 | "Norfolk Island",
1018 | "Nigeria",
1019 | "Nicaragua",
1020 | "Netherlands",
1021 | "Norway",
1022 | "Nepal",
1023 | "Nauru",
1024 | "Niue",
1025 | "New Zealand",
1026 | "Oman",
1027 | "Panama",
1028 | "Peru",
1029 | "French Polynesia",
1030 | "Papua New Guinea",
1031 | "Philippines",
1032 | "Pakistan",
1033 | "Poland",
1034 | "Saint Pierre and Miquelon",
1035 | "Pitcairn Islands",
1036 | "Puerto Rico",
1037 | "Palestinian Territory",
1038 | "Portugal",
1039 | "Palau",
1040 | "Paraguay",
1041 | "Qatar",
1042 | "Reunion",
1043 | "Romania",
1044 | "Russian Federation",
1045 | "Rwanda",
1046 | "Saudi Arabia",
1047 | "Solomon Islands",
1048 | "Seychelles",
1049 | "Sudan",
1050 | "Sweden",
1051 | "Singapore",
1052 | "Saint Helena",
1053 | "Slovenia",
1054 | "Svalbard and Jan Mayen",
1055 | "Slovakia",
1056 | "Sierra Leone",
1057 | "San Marino",
1058 | "Senegal",
1059 | "Somalia",
1060 | "Suriname",
1061 | "Sao Tome and Principe",
1062 | "El Salvador",
1063 | "Syrian Arab Republic",
1064 | "Swaziland",
1065 | "Turks and Caicos Islands",
1066 | "Chad",
1067 | "French Southern Territories",
1068 | "Togo",
1069 | "Thailand",
1070 | "Tajikistan",
1071 | "Tokelau",
1072 | "Turkmenistan",
1073 | "Tunisia",
1074 | "Tonga",
1075 | "Timor-Leste",
1076 | "Turkey",
1077 | "Trinidad and Tobago",
1078 | "Tuvalu",
1079 | "Taiwan",
1080 | "Tanzania, United Republic of",
1081 | "Ukraine",
1082 | "Uganda",
1083 | "United States Minor Outlying Islands",
1084 | "United States",
1085 | "Uruguay",
1086 | "Uzbekistan",
1087 | "Holy See (Vatican City State)",
1088 | "Saint Vincent and the Grenadines",
1089 | "Venezuela",
1090 | "Virgin Islands, British",
1091 | "Virgin Islands, U.S.",
1092 | "Vietnam",
1093 | "Vanuatu",
1094 | "Wallis and Futuna",
1095 | "Samoa",
1096 | "Yemen",
1097 | "Mayotte",
1098 | "Serbia",
1099 | "South Africa",
1100 | "Zambia",
1101 | "Montenegro",
1102 | "Zimbabwe",
1103 | "Anonymous Proxy",
1104 | "Satellite Provider",
1105 | "Other",
1106 | "Aland Islands",
1107 | "Guernsey",
1108 | "Isle of Man",
1109 | "Jersey",
1110 | "Saint Barthelemy",
1111 | "Saint Martin",
1112 | "Bonaire, Saint Eustatius and Saba",
1113 | "South Sudan",
1114 | "Other"
1115 | );
1116 |
1117 | public $GEOIP_CONTINENT_CODES = array(
1118 | "--",
1119 | "AS",
1120 | "EU",
1121 | "EU",
1122 | "AS",
1123 | "AS",
1124 | "NA",
1125 | "NA",
1126 | "EU",
1127 | "AS",
1128 | "NA",
1129 | "AF",
1130 | "AN",
1131 | "SA",
1132 | "OC",
1133 | "EU",
1134 | "OC",
1135 | "NA",
1136 | "AS",
1137 | "EU",
1138 | "NA",
1139 | "AS",
1140 | "EU",
1141 | "AF",
1142 | "EU",
1143 | "AS",
1144 | "AF",
1145 | "AF",
1146 | "NA",
1147 | "AS",
1148 | "SA",
1149 | "SA",
1150 | "NA",
1151 | "AS",
1152 | "AN",
1153 | "AF",
1154 | "EU",
1155 | "NA",
1156 | "NA",
1157 | "AS",
1158 | "AF",
1159 | "AF",
1160 | "AF",
1161 | "EU",
1162 | "AF",
1163 | "OC",
1164 | "SA",
1165 | "AF",
1166 | "AS",
1167 | "SA",
1168 | "NA",
1169 | "NA",
1170 | "AF",
1171 | "AS",
1172 | "AS",
1173 | "EU",
1174 | "EU",
1175 | "AF",
1176 | "EU",
1177 | "NA",
1178 | "NA",
1179 | "AF",
1180 | "SA",
1181 | "EU",
1182 | "AF",
1183 | "AF",
1184 | "AF",
1185 | "EU",
1186 | "AF",
1187 | "EU",
1188 | "OC",
1189 | "SA",
1190 | "OC",
1191 | "EU",
1192 | "EU",
1193 | "NA",
1194 | "AF",
1195 | "EU",
1196 | "NA",
1197 | "AS",
1198 | "SA",
1199 | "AF",
1200 | "EU",
1201 | "NA",
1202 | "AF",
1203 | "AF",
1204 | "NA",
1205 | "AF",
1206 | "EU",
1207 | "AN",
1208 | "NA",
1209 | "OC",
1210 | "AF",
1211 | "SA",
1212 | "AS",
1213 | "AN",
1214 | "NA",
1215 | "EU",
1216 | "NA",
1217 | "EU",
1218 | "AS",
1219 | "EU",
1220 | "AS",
1221 | "AS",
1222 | "AS",
1223 | "AS",
1224 | "AS",
1225 | "EU",
1226 | "EU",
1227 | "NA",
1228 | "AS",
1229 | "AS",
1230 | "AF",
1231 | "AS",
1232 | "AS",
1233 | "OC",
1234 | "AF",
1235 | "NA",
1236 | "AS",
1237 | "AS",
1238 | "AS",
1239 | "NA",
1240 | "AS",
1241 | "AS",
1242 | "AS",
1243 | "NA",
1244 | "EU",
1245 | "AS",
1246 | "AF",
1247 | "AF",
1248 | "EU",
1249 | "EU",
1250 | "EU",
1251 | "AF",
1252 | "AF",
1253 | "EU",
1254 | "EU",
1255 | "AF",
1256 | "OC",
1257 | "EU",
1258 | "AF",
1259 | "AS",
1260 | "AS",
1261 | "AS",
1262 | "OC",
1263 | "NA",
1264 | "AF",
1265 | "NA",
1266 | "EU",
1267 | "AF",
1268 | "AS",
1269 | "AF",
1270 | "NA",
1271 | "AS",
1272 | "AF",
1273 | "AF",
1274 | "OC",
1275 | "AF",
1276 | "OC",
1277 | "AF",
1278 | "NA",
1279 | "EU",
1280 | "EU",
1281 | "AS",
1282 | "OC",
1283 | "OC",
1284 | "OC",
1285 | "AS",
1286 | "NA",
1287 | "SA",
1288 | "OC",
1289 | "OC",
1290 | "AS",
1291 | "AS",
1292 | "EU",
1293 | "NA",
1294 | "OC",
1295 | "NA",
1296 | "AS",
1297 | "EU",
1298 | "OC",
1299 | "SA",
1300 | "AS",
1301 | "AF",
1302 | "EU",
1303 | "EU",
1304 | "AF",
1305 | "AS",
1306 | "OC",
1307 | "AF",
1308 | "AF",
1309 | "EU",
1310 | "AS",
1311 | "AF",
1312 | "EU",
1313 | "EU",
1314 | "EU",
1315 | "AF",
1316 | "EU",
1317 | "AF",
1318 | "AF",
1319 | "SA",
1320 | "AF",
1321 | "NA",
1322 | "AS",
1323 | "AF",
1324 | "NA",
1325 | "AF",
1326 | "AN",
1327 | "AF",
1328 | "AS",
1329 | "AS",
1330 | "OC",
1331 | "AS",
1332 | "AF",
1333 | "OC",
1334 | "AS",
1335 | "EU",
1336 | "NA",
1337 | "OC",
1338 | "AS",
1339 | "AF",
1340 | "EU",
1341 | "AF",
1342 | "OC",
1343 | "NA",
1344 | "SA",
1345 | "AS",
1346 | "EU",
1347 | "NA",
1348 | "SA",
1349 | "NA",
1350 | "NA",
1351 | "AS",
1352 | "OC",
1353 | "OC",
1354 | "OC",
1355 | "AS",
1356 | "AF",
1357 | "EU",
1358 | "AF",
1359 | "AF",
1360 | "EU",
1361 | "AF",
1362 | "--",
1363 | "--",
1364 | "--",
1365 | "EU",
1366 | "EU",
1367 | "EU",
1368 | "EU",
1369 | "NA",
1370 | "NA",
1371 | "NA",
1372 | "AF",
1373 | "--"
1374 | );
1375 | }
1376 |
1377 | function geoip_load_shared_mem($file)
1378 | {
1379 | $fp = fopen($file, "rb");
1380 | if (!$fp) {
1381 | print "error opening $file: $php_errormsg\n";
1382 | exit;
1383 | }
1384 | $s_array = fstat($fp);
1385 | $size = $s_array['size'];
1386 | if (($shmid = @shmop_open(GEOIP_SHM_KEY, "w", 0, 0))) {
1387 | shmop_delete($shmid);
1388 | shmop_close($shmid);
1389 | }
1390 | $shmid = shmop_open(GEOIP_SHM_KEY, "c", 0644, $size);
1391 | shmop_write($shmid, fread($fp, $size), 0);
1392 | shmop_close($shmid);
1393 | }
1394 |
1395 | function _setup_segments($gi)
1396 | {
1397 | $gi->databaseType = GEOIP_COUNTRY_EDITION;
1398 | $gi->record_length = STANDARD_RECORD_LENGTH;
1399 | if ($gi->flags & GEOIP_SHARED_MEMORY) {
1400 | $offset = @shmop_size($gi->shmid) - 3;
1401 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
1402 | $delim = @shmop_read($gi->shmid, $offset, 3);
1403 | $offset += 3;
1404 | if ($delim == (chr(255) . chr(255) . chr(255))) {
1405 | $gi->databaseType = ord(@shmop_read($gi->shmid, $offset, 1));
1406 | if ($gi->databaseType >= 106) {
1407 | $gi->databaseType -= 105;
1408 | }
1409 | $offset++;
1410 |
1411 | if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) {
1412 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
1413 | } elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
1414 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
1415 | } elseif (($gi->databaseType == GEOIP_CITY_EDITION_REV0)
1416 | || ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
1417 | || ($gi->databaseType == GEOIP_ORG_EDITION)
1418 | || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
1419 | || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
1420 | || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
1421 | || ($gi->databaseType == GEOIP_ISP_EDITION)
1422 | || ($gi->databaseType == GEOIP_ISP_EDITION_V6)
1423 | || ($gi->databaseType == GEOIP_USERTYPE_EDITION)
1424 | || ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6)
1425 | || ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
1426 | || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
1427 | || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
1428 | || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
1429 | || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1)
1430 | || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6)
1431 | || ($gi->databaseType == GEOIP_ASNUM_EDITION)
1432 | || ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)
1433 | ) {
1434 | $gi->databaseSegments = 0;
1435 | $buf = @shmop_read($gi->shmid, $offset, SEGMENT_RECORD_LENGTH);
1436 | for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) {
1437 | $gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
1438 | }
1439 | if (($gi->databaseType == GEOIP_ORG_EDITION)
1440 | || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
1441 | || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
1442 | || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
1443 | || ($gi->databaseType == GEOIP_ISP_EDITION)
1444 | || ($gi->databaseType == GEOIP_ISP_EDITION_V6)
1445 | ) {
1446 | $gi->record_length = ORG_RECORD_LENGTH;
1447 | }
1448 | }
1449 | break;
1450 | } else {
1451 | $offset -= 4;
1452 | }
1453 | }
1454 | if (($gi->databaseType == GEOIP_COUNTRY_EDITION) ||
1455 | ($gi->databaseType == GEOIP_COUNTRY_EDITION_V6) ||
1456 | ($gi->databaseType == GEOIP_PROXY_EDITION) ||
1457 | ($gi->databaseType == GEOIP_NETSPEED_EDITION)
1458 | ) {
1459 | $gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
1460 | }
1461 | } else {
1462 | $filepos = ftell($gi->filehandle);
1463 | fseek($gi->filehandle, -3, SEEK_END);
1464 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
1465 | $delim = fread($gi->filehandle, 3);
1466 | if ($delim == (chr(255) . chr(255) . chr(255))) {
1467 | $gi->databaseType = ord(fread($gi->filehandle, 1));
1468 | if ($gi->databaseType >= 106) {
1469 | $gi->databaseType -= 105;
1470 | }
1471 | if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) {
1472 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
1473 | } elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
1474 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
1475 | } elseif (($gi->databaseType == GEOIP_CITY_EDITION_REV0)
1476 | || ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
1477 | || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
1478 | || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
1479 | || ($gi->databaseType == GEOIP_ORG_EDITION)
1480 | || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
1481 | || ($gi->databaseType == GEOIP_ISP_EDITION)
1482 | || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
1483 | || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
1484 | || ($gi->databaseType == GEOIP_ISP_EDITION_V6)
1485 | || ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
1486 | || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
1487 | || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
1488 | || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
1489 | || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1)
1490 | || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6)
1491 | || ($gi->databaseType == GEOIP_USERTYPE_EDITION)
1492 | || ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6)
1493 | || ($gi->databaseType == GEOIP_ASNUM_EDITION)
1494 | || ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)
1495 | ) {
1496 | $gi->databaseSegments = 0;
1497 | $buf = fread($gi->filehandle, SEGMENT_RECORD_LENGTH);
1498 | for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) {
1499 | $gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
1500 | }
1501 | if (($gi->databaseType == GEOIP_ORG_EDITION)
1502 | || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
1503 | || ($gi->databaseType == GEOIP_ISP_EDITION)
1504 | || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
1505 | || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
1506 | || ($gi->databaseType == GEOIP_ISP_EDITION_V6)
1507 | ) {
1508 | $gi->record_length = ORG_RECORD_LENGTH;
1509 | }
1510 | }
1511 | break;
1512 | } else {
1513 | fseek($gi->filehandle, -4, SEEK_CUR);
1514 | }
1515 | }
1516 | if (($gi->databaseType == GEOIP_COUNTRY_EDITION) ||
1517 | ($gi->databaseType == GEOIP_COUNTRY_EDITION_V6) ||
1518 | ($gi->databaseType == GEOIP_PROXY_EDITION) ||
1519 | ($gi->databaseType == GEOIP_NETSPEED_EDITION)
1520 | ) {
1521 | $gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
1522 | }
1523 | fseek($gi->filehandle, $filepos, SEEK_SET);
1524 | }
1525 | return $gi;
1526 | }
1527 |
1528 | function geoip_open($filename, $flags)
1529 | {
1530 | $gi = new GeoIP;
1531 | $gi->flags = $flags;
1532 | if ($gi->flags & GEOIP_SHARED_MEMORY) {
1533 | $gi->shmid = @shmop_open(GEOIP_SHM_KEY, "a", 0, 0);
1534 | } else {
1535 | $gi->filehandle = fopen($filename, "rb") or trigger_error("GeoIP API: Can not open $filename\n", E_USER_ERROR);
1536 | if ($gi->flags & GEOIP_MEMORY_CACHE) {
1537 | $s_array = fstat($gi->filehandle);
1538 | $gi->memory_buffer = fread($gi->filehandle, $s_array['size']);
1539 | }
1540 | }
1541 |
1542 | $gi = _setup_segments($gi);
1543 | return $gi;
1544 | }
1545 |
1546 | function geoip_close($gi)
1547 | {
1548 | if ($gi->flags & GEOIP_SHARED_MEMORY) {
1549 | return true;
1550 | }
1551 |
1552 | return fclose($gi->filehandle);
1553 | }
1554 |
1555 | function geoip_country_id_by_name_v6($gi, $name)
1556 | {
1557 | $rec = dns_get_record($name, DNS_AAAA);
1558 | if (!$rec) {
1559 | return false;
1560 | }
1561 | $addr = $rec[0]["ipv6"];
1562 | if (!$addr || $addr == $name) {
1563 | return false;
1564 | }
1565 | return geoip_country_id_by_addr_v6($gi, $addr);
1566 | }
1567 |
1568 | function geoip_country_id_by_name($gi, $name)
1569 | {
1570 | $addr = gethostbyname($name);
1571 | if (!$addr || $addr == $name) {
1572 | return false;
1573 | }
1574 | return geoip_country_id_by_addr($gi, $addr);
1575 | }
1576 |
1577 | function geoip_country_code_by_name_v6($gi, $name)
1578 | {
1579 | $country_id = geoip_country_id_by_name_v6($gi, $name);
1580 | if ($country_id !== false) {
1581 | return $gi->GEOIP_COUNTRY_CODES[$country_id];
1582 | }
1583 | return false;
1584 | }
1585 |
1586 | function geoip_country_code_by_name($gi, $name)
1587 | {
1588 | $country_id = geoip_country_id_by_name($gi, $name);
1589 | if ($country_id !== false) {
1590 | return $gi->GEOIP_COUNTRY_CODES[$country_id];
1591 | }
1592 | return false;
1593 | }
1594 |
1595 | function geoip_country_name_by_name_v6($gi, $name)
1596 | {
1597 | $country_id = geoip_country_id_by_name_v6($gi, $name);
1598 | if ($country_id !== false) {
1599 | return $gi->GEOIP_COUNTRY_NAMES[$country_id];
1600 | }
1601 | return false;
1602 | }
1603 |
1604 | function geoip_country_name_by_name($gi, $name)
1605 | {
1606 | $country_id = geoip_country_id_by_name($gi, $name);
1607 | if ($country_id !== false) {
1608 | return $gi->GEOIP_COUNTRY_NAMES[$country_id];
1609 | }
1610 | return false;
1611 | }
1612 |
1613 | function geoip_country_id_by_addr_v6($gi, $addr)
1614 | {
1615 | $ipnum = inet_pton($addr);
1616 | return _geoip_seek_country_v6($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
1617 | }
1618 |
1619 | function geoip_country_id_by_addr($gi, $addr)
1620 | {
1621 | $ipnum = ip2long($addr);
1622 | return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
1623 | }
1624 |
1625 | function geoip_country_code_by_addr_v6($gi, $addr)
1626 | {
1627 | $country_id = geoip_country_id_by_addr_v6($gi, $addr);
1628 | if ($country_id !== false) {
1629 | return $gi->GEOIP_COUNTRY_CODES[$country_id];
1630 | }
1631 | return false;
1632 | }
1633 |
1634 | function geoip_country_code_by_addr($gi, $addr)
1635 | {
1636 | if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
1637 | $record = geoip_record_by_addr($gi, $addr);
1638 | if ($record !== false) {
1639 | return $record->country_code;
1640 | }
1641 | } else {
1642 | $country_id = geoip_country_id_by_addr($gi, $addr);
1643 | if ($country_id !== false) {
1644 | return $gi->GEOIP_COUNTRY_CODES[$country_id];
1645 | }
1646 | }
1647 | return false;
1648 | }
1649 |
1650 | function geoip_country_name_by_addr_v6($gi, $addr)
1651 | {
1652 | $country_id = geoip_country_id_by_addr_v6($gi, $addr);
1653 | if ($country_id !== false) {
1654 | return $gi->GEOIP_COUNTRY_NAMES[$country_id];
1655 | }
1656 | return false;
1657 | }
1658 |
1659 | function geoip_country_name_by_addr($gi, $addr)
1660 | {
1661 | if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
1662 | $record = geoip_record_by_addr($gi, $addr);
1663 | return $record->country_name;
1664 | } else {
1665 | $country_id = geoip_country_id_by_addr($gi, $addr);
1666 | if ($country_id !== false) {
1667 | return $gi->GEOIP_COUNTRY_NAMES[$country_id];
1668 | }
1669 | }
1670 | return false;
1671 | }
1672 |
1673 | function _geoip_seek_country_v6($gi, $ipnum)
1674 | {
1675 | # arrays from unpack start with offset 1
1676 | # yet another php mystery. array_merge work around
1677 | # this broken behaviour
1678 | $v6vec = array_merge(unpack("C16", $ipnum));
1679 |
1680 | $offset = 0;
1681 | for ($depth = 127; $depth >= 0; --$depth) {
1682 | if ($gi->flags & GEOIP_MEMORY_CACHE) {
1683 | $buf = _safe_substr(
1684 | $gi->memory_buffer,
1685 | 2 * $gi->record_length * $offset,
1686 | 2 * $gi->record_length
1687 | );
1688 | } elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
1689 | $buf = @shmop_read(
1690 | $gi->shmid,
1691 | 2 * $gi->record_length * $offset,
1692 | 2 * $gi->record_length
1693 | );
1694 | } else {
1695 | fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
1696 | or trigger_error("GeoIP API: fseek failed", E_USER_ERROR);
1697 | $buf = fread($gi->filehandle, 2 * $gi->record_length);
1698 | }
1699 | $x = array(0, 0);
1700 | for ($i = 0; $i < 2; ++$i) {
1701 | for ($j = 0; $j < $gi->record_length; ++$j) {
1702 | $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
1703 | }
1704 | }
1705 |
1706 | $bnum = 127 - $depth;
1707 | $idx = $bnum >> 3;
1708 | $b_mask = 1 << ($bnum & 7 ^ 7);
1709 | if (($v6vec[$idx] & $b_mask) > 0) {
1710 | if ($x[1] >= $gi->databaseSegments) {
1711 | return $x[1];
1712 | }
1713 | $offset = $x[1];
1714 | } else {
1715 | if ($x[0] >= $gi->databaseSegments) {
1716 | return $x[0];
1717 | }
1718 | $offset = $x[0];
1719 | }
1720 | }
1721 | trigger_error("GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR);
1722 | return false;
1723 | }
1724 |
1725 | function _geoip_seek_country($gi, $ipnum)
1726 | {
1727 | $offset = 0;
1728 | for ($depth = 31; $depth >= 0; --$depth) {
1729 | if ($gi->flags & GEOIP_MEMORY_CACHE) {
1730 | $buf = _safe_substr(
1731 | $gi->memory_buffer,
1732 | 2 * $gi->record_length * $offset,
1733 | 2 * $gi->record_length
1734 | );
1735 | } elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
1736 | $buf = @shmop_read(
1737 | $gi->shmid,
1738 | 2 * $gi->record_length * $offset,
1739 | 2 * $gi->record_length
1740 | );
1741 | } else {
1742 | fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
1743 | or trigger_error("GeoIP API: fseek failed", E_USER_ERROR);
1744 | $buf = fread($gi->filehandle, 2 * $gi->record_length);
1745 | }
1746 | $x = array(0, 0);
1747 | for ($i = 0; $i < 2; ++$i) {
1748 | for ($j = 0; $j < $gi->record_length; ++$j) {
1749 | $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
1750 | }
1751 | }
1752 | if ($ipnum & (1 << $depth)) {
1753 | if ($x[1] >= $gi->databaseSegments) {
1754 | return $x[1];
1755 | }
1756 | $offset = $x[1];
1757 | } else {
1758 | if ($x[0] >= $gi->databaseSegments) {
1759 | return $x[0];
1760 | }
1761 | $offset = $x[0];
1762 | }
1763 | }
1764 | trigger_error("GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR);
1765 | return false;
1766 | }
1767 |
1768 | function _common_get_org($gi, $seek_org)
1769 | {
1770 | $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments;
1771 | if ($gi->flags & GEOIP_SHARED_MEMORY) {
1772 | $org_buf = @shmop_read($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH);
1773 | } else {
1774 | fseek($gi->filehandle, $record_pointer, SEEK_SET);
1775 | $org_buf = fread($gi->filehandle, MAX_ORG_RECORD_LENGTH);
1776 | }
1777 | $org_buf = _safe_substr($org_buf, 0, strpos($org_buf, "\0"));
1778 | return $org_buf;
1779 | }
1780 |
1781 | function _get_org_v6($gi, $ipnum)
1782 | {
1783 | $seek_org = _geoip_seek_country_v6($gi, $ipnum);
1784 | if ($seek_org == $gi->databaseSegments) {
1785 | return null;
1786 | }
1787 | return _common_get_org($gi, $seek_org);
1788 | }
1789 |
1790 | function _get_org($gi, $ipnum)
1791 | {
1792 | $seek_org = _geoip_seek_country($gi, $ipnum);
1793 | if ($seek_org == $gi->databaseSegments) {
1794 | return null;
1795 | }
1796 | return _common_get_org($gi, $seek_org);
1797 | }
1798 |
1799 |
1800 | function geoip_name_by_addr_v6($gi, $addr)
1801 | {
1802 | if ($addr == null) {
1803 | return 0;
1804 | }
1805 | $ipnum = inet_pton($addr);
1806 | return _get_org_v6($gi, $ipnum);
1807 | }
1808 |
1809 | function geoip_name_by_addr($gi, $addr)
1810 | {
1811 | if ($addr == null) {
1812 | return 0;
1813 | }
1814 | $ipnum = ip2long($addr);
1815 | return _get_org($gi, $ipnum);
1816 | }
1817 |
1818 | function geoip_org_by_addr($gi, $addr)
1819 | {
1820 | return geoip_name_by_addr($gi, $addr);
1821 | }
1822 |
1823 | function _get_region($gi, $ipnum)
1824 | {
1825 | if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) {
1826 | $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV0;
1827 | if ($seek_region >= 1000) {
1828 | $country_code = "US";
1829 | $region = chr(($seek_region - 1000) / 26 + 65) . chr(($seek_region - 1000) % 26 + 65);
1830 | } else {
1831 | $country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region];
1832 | $region = "";
1833 | }
1834 | return array($country_code, $region);
1835 | } elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
1836 | $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV1;
1837 | if ($seek_region < US_OFFSET) {
1838 | $country_code = "";
1839 | $region = "";
1840 | } elseif ($seek_region < CANADA_OFFSET) {
1841 | $country_code = "US";
1842 | $region = chr(($seek_region - US_OFFSET) / 26 + 65) . chr(($seek_region - US_OFFSET) % 26 + 65);
1843 | } elseif ($seek_region < WORLD_OFFSET) {
1844 | $country_code = "CA";
1845 | $region = chr(($seek_region - CANADA_OFFSET) / 26 + 65) . chr(($seek_region - CANADA_OFFSET) % 26 + 65);
1846 | } else {
1847 | $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE];
1848 | $region = "";
1849 | }
1850 | return array($country_code, $region);
1851 | }
1852 | }
1853 |
1854 | function geoip_region_by_addr($gi, $addr)
1855 | {
1856 | if ($addr == null) {
1857 | return 0;
1858 | }
1859 | $ipnum = ip2long($addr);
1860 | return _get_region($gi, $ipnum);
1861 | }
1862 |
1863 | function _safe_substr($string, $start, $length)
1864 | {
1865 | // workaround php's broken substr, strpos, etc handling with
1866 | // mbstring.func_overload and mbstring.internal_encoding
1867 | $mbExists = extension_loaded('mbstring');
1868 |
1869 | if ($mbExists) {
1870 | $enc = mb_internal_encoding();
1871 | mb_internal_encoding('ISO-8859-1');
1872 | }
1873 |
1874 | $buf = substr($string, $start, $length);
1875 |
1876 | if ($mbExists) {
1877 | mb_internal_encoding($enc);
1878 | }
1879 |
1880 | return $buf;
1881 | }
1882 |
--------------------------------------------------------------------------------
/src/timezone.php:
--------------------------------------------------------------------------------
1 |