Skip to content

Commit

Permalink
Update GeoLite2-City.mmdb, add test _backend page
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisgoddard committed Mar 21, 2024
1 parent 01c102a commit 2043fd7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
Binary file modified _backend/GeoLite2-City.mmdb
Binary file not shown.
5 changes: 4 additions & 1 deletion _backend/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"config": {
"platform": {
"php": "8.1"
},
"allow-plugins": {
"php-http/discovery": true
}
},
"autoload": {
Expand All @@ -22,4 +25,4 @@
"league/climate": "^3.2",
"squizlabs/php_codesniffer": "3.*"
}
}
}
27 changes: 0 additions & 27 deletions _backend/geolocate.functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,6 @@ function getIPHash($hostname, $debug = false)
}
}

function getCurrentCountry($hostname, $debug = false)
{

try {
if (!class_exists('GeoIp2\Database\Reader')) {
throw new \Exception('Class GeoIp2\Database\Reader not found');
}
$reader = new Reader(__DIR__.'/GeoLite2-City.mmdb');
$record = $reader->city($hostname);
$country = $record->country->isoCode;
} catch (\Exception $e) {
if ($debug) {
echo $e->getMessage();
} else {
error_log($e->getMessage());
}
$country = false;
}

if ($debug) {
echo 'Country: "'.$country.'"'."\n";
}

return $country;
}


function getCurrentLocation($hostname, $debug = false)
{

Expand Down
13 changes: 13 additions & 0 deletions _backend/geolocate.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require_once __DIR__.'/geolocate.functions.php';
require_once __DIR__.'/geolocate.guess_ip.php';

$region = getDownloadRegion($ip);
$hash = getIPHash($ip);
if (is_array($region)) {
$region = $region[$hash];
}
$currentLocation = getCurrentLocation($ip);

var_dump($ip, $region, $hash, $currentLocation);

0 comments on commit 2043fd7

Please sign in to comment.