修复判断入口文件ip_check.php以及新增复制配置选项

This commit is contained in:
root
2026-06-15 16:53:05 +08:00
parent 8f46a4c1c4
commit 1a52201ec7
23 changed files with 969 additions and 35 deletions
+9 -4
View File
@@ -1,4 +1,6 @@
<?php
require_once __DIR__ . '/CountryCodeNormalizer.php';
class GeoIpCountryResolver
{
/** @var GeoIp2\Database\Reader|null */
@@ -73,11 +75,14 @@ class GeoIpCountryResolver
}
try {
$record = $reader->country($ip);
$code = $record->country->isoCode ?? null;
if ($code === null || $code === '') {
return null;
$isoCode = $record->country->isoCode ?? null;
$name = $record->country->name ?? null;
$code = CountryCodeNormalizer::toAlpha2($isoCode);
if ($code === null && $name !== null && $name !== '') {
$code = CountryCodeNormalizer::toAlpha2($name);
}
return strtoupper((string) $code);
return $code;
} catch (GeoIp2\Exception\AddressNotFoundException $e) {
return null;
} catch (Throwable $e) {