Skip to content

Commit

Permalink
[FEATURE] Introduce proxy support. Resolves issue #51
Browse files Browse the repository at this point in the history
  • Loading branch information
MFabse committed Feb 15, 2024
1 parent 5c19477 commit a811f86
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Classes/Utility/LocateUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a811f86

Please sign in to comment.