t
This commit is contained in:
21
location-ip-to-location.php
Normal file
21
location-ip-to-location.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
require '.hta_lib/vendors/maxmind-db-reader/vendor/autoload.php';
|
||||
|
||||
use GeoIp2\Database\Reader;
|
||||
|
||||
if (isset($_GET['ip'])) {
|
||||
try {
|
||||
$reader = new Reader('.hta_lib/data/GeoLite2-City.mmdb');
|
||||
|
||||
$records = $reader->city($_GET['ip']);
|
||||
|
||||
$city = $records->city->name;
|
||||
|
||||
echo json_encode(['city' => $city]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['error' => $e->getMessage()]);
|
||||
}
|
||||
} else {
|
||||
echo json_encode(['error' => 'Invalid parameters']);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user