mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 10:37:30 -07:00
Minor improvements (#1481)
* Minor improvements * Updated * Update functions.php * Updated * Update .gitignore * Updated * Update CHANGELOG.md
This commit is contained in:
parent
9ada2c63b9
commit
f584cf5d29
11 changed files with 10 additions and 108 deletions
|
@ -2166,26 +2166,17 @@ function readUpdaterFile(): array|bool
|
|||
}
|
||||
|
||||
/**
|
||||
* Show country ISO Code by user IP address
|
||||
* IP Geolocation API
|
||||
*
|
||||
* @param string $ipAddress
|
||||
* @param int $port
|
||||
* @return mixed|string|null
|
||||
*/
|
||||
function getCountryByIP(string $ipAddress, int $port = 1111): mixed
|
||||
function infoByIP(string $ipAddress, int $port = 0): mixed
|
||||
{
|
||||
global $lang;
|
||||
|
||||
if (!$data = CACHE('bb_ip2countries')->get($ipAddress . '_' . $port)) {
|
||||
$cityDbReader = new \GeoIp2\Database\Reader(INT_DATA_DIR . '/GeoLite2-City.mmdb');
|
||||
try {
|
||||
$record = $cityDbReader->city($ipAddress);
|
||||
$data = $record->country->isoCode;
|
||||
} catch (\GeoIp2\Exception\AddressNotFoundException $e) {
|
||||
$data = $lang['UNKNOWN'];
|
||||
} catch (\MaxMind\Db\Reader\InvalidDatabaseException $e) {
|
||||
bb_die($e->getMessage());
|
||||
}
|
||||
$response = file_get_contents(API_IP_URL . $ipAddress);
|
||||
$data = json_decode($response, true);
|
||||
CACHE('bb_ip2countries')->set($ipAddress . '_' . $port, $data, 1200);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue