Commit 781e82cbca
781e82cbcad9f12838f01c687979027823c1937c
parent: 52987d8d08
Unsigned
cmc <hello@cleberg.net> · 2026-08-22 23:43 UTC
Untrack the GeoLite2 database and vendor/
GeoLite2-City.mmdb was 69 MB of the repo's ~69 MB. It is MaxMind-licensed with
attribution terms and stale the day after it is downloaded, so it does not
belong in git; README.nfo now says where to get it. vendor/ goes too —
composer.lock already pins it.
Since the database is no longer present by default, a missing one now returns
null instead of throwing, and the geo fields are null-coalesced, so the page
serves without the geolocation block rather than failing.
The source link pointed at git.cleberg.net, which no longer resolves.
Layout: unified · split
.gitignore
added
+8
| @@ -0,0 +1,8 @@ |
| 1 | # Composer installs these; composer.lock pins them. |
| 2 | vendor/ |
| 3 | |
| 4 | # MaxMind GeoLite2. Licensed, ~69 MB, and stale the day after it is downloaded — |
| 5 | # see README.nfo for how to fetch it. Never commit it. |
| 6 | *.mmdb |
| 7 | |
| 8 | .DS_Store |
README.nfo
+8
| @@ -36,6 +36,14 @@ DEVELOP |
| 36 | 36 | composer require maxmind-db/reader:~1.0 |
| 37 | 37 | composer update |
| 38 | 38 | |
| 39 | geolite2 database. not in the repo: maxmind-licensed, ~69mb, and stale |
| 40 | the day after you download it. sign up for a free maxmind account, then: |
| 41 | |
| 42 | https://www.maxmind.com/en/accounts/current/geoip/downloads |
| 43 | |
| 44 | download GeoLite2-City in mmdb form and put GeoLite2-City.mmdb next to |
| 45 | ifconfig.php. without it the page still serves, minus the geo block. |
| 46 | |
| 39 | 47 | dev server: |
| 40 | 48 | |
| 41 | 49 | sudo php --server localhost:8080 --docroot . |
ifconfig.php
+14 −7
| @@ -6,6 +6,13 @@ use MaxMind\Db\Reader; |
| 6 | 6 | function loadGeo(string $ipAddress): ?array |
| 7 | 7 | { |
| 8 | 8 | $databaseFile = 'GeoLite2-City.mmdb'; |
| 9 | |
| 10 | // Not shipped with the source: it is MaxMind-licensed and ~69 MB. Without |
| 11 | // it the page still serves, just with no geolocation block. |
| 12 | if (!is_readable($databaseFile)) { |
| 13 | return null; |
| 14 | } |
| 15 | |
| 9 | 16 | $reader = new Reader($databaseFile); |
| 10 | 17 | $results = $reader->get($ipAddress); |
| 11 | 18 | $reader->close(); |
| @@ -17,7 +24,7 @@ function loadGeo(string $ipAddress): ?array |
| 17 | 24 | $site_title = 'ip.cleberg.net'; |
| 18 | 25 | $site_owner_name = 'Christian Cleberg'; |
| 19 | 26 | $site_owner_url = 'https://cleberg.net'; |
| 20 | | $source_repository = 'https://git.cleberg.net/ifconfig.php.git'; |
| 27 | $source_repository = 'https://github.com/krazywarez/ifconfig.php'; |
| 21 | 28 | |
| 22 | 29 | // Extract geolocation |
| 23 | 30 | $geo = loadGeo($_SERVER['REMOTE_ADDR']); |
| @@ -40,12 +47,12 @@ $user = array( |
| 40 | 47 | 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'], |
| 41 | 48 | 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""), |
| 42 | 49 | 'dnt' => $_SERVER['HTTP_DNT'], |
| 43 | | 'continent_code' => $geo['continent']['code'], |
| 44 | | 'continent_name' => $geo['continent']['names']['en'], |
| 45 | | 'country_code' => $geo['country']['geoname_id'], |
| 46 | | 'country_iso' => $geo['country']['iso_code'], |
| 47 | | 'country_name' => $geo['country']['names']['en'], |
| 48 | | 'time_zone' => $geo['location']['time_zone'] |
| 50 | 'continent_code' => $geo['continent']['code'] ?? '', |
| 51 | 'continent_name' => $geo['continent']['names']['en'] ?? '', |
| 52 | 'country_code' => $geo['country']['geoname_id'] ?? '', |
| 53 | 'country_iso' => $geo['country']['iso_code'] ?? '', |
| 54 | 'country_name' => $geo['country']['names']['en'] ?? '', |
| 55 | 'time_zone' => $geo['location']['time_zone'] ?? '' |
| 49 | 56 | ); |
| 50 | 57 | |
| 51 | 58 | // Check request (ex. ifconfig.php?q=ip) |