diff --git a/Classes/Utility/LocateUtility.php b/Classes/Utility/LocateUtility.php index da13f60..815a7d3 100644 --- a/Classes/Utility/LocateUtility.php +++ b/Classes/Utility/LocateUtility.php @@ -44,11 +44,26 @@ public function getCountryIso2FromIP(?string $ip = null): bool|string public function getNumericIp(?string $ip = null): string|bool { - $ip = $ip ?? (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'); + $ip = $ip ?? $this->getRemoteAddress(); return str_contains($ip, '.') ? (string)ip2long($ip) : $this->convertIpv6($ip); } + protected function getRemoteAddress(): ?string + { + $remoteAddr = $this->getHeader('X-Forwarded-For'); + if (!empty($remoteAddr)) { + return $remoteAddr; + } + return (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'); + } + + protected function getHeader(string $headerName): ?string + { + $headers = getallheaders(); + return $headers[$headerName] ?? null; + } + private function convertIpv6(string $ip): string|bool { $ip = inet_pton($ip);