src/Viserio/Component/Support/Http/ClientIp.php
private function getFirstIpAddressFromHeader(ServerRequestInterface $serverRequest, string $header): string
    {
        $items       = \explode(',', $serverRequest->getHeaderLine($header));
        $headerValue = \trim(\reset($items));

        if (\ucfirst($header) === 'Forwarded') {
            foreach (\explode(';', $headerValue) as $headerPart) {
                if (\mb_strtolower(\mb_substr($headerPart, 0, 4)) === 'for=') {
                    $for         = \explode(']', $headerPart);
                    $headerValue = \trim(\mb_substr(\reset($for), 4), " \t\n\r\0\x0B" . '"[]');

                    break;
                }
            }
        }

        return $headerValue;
    }
private function getFirstIpAddressFromHeader(ServerRequestInterface $serverRequest, string $header): string
    {
        $items       = \explode(',', $serverRequest->getHeaderLine($header));
        $headerValue = \trim(\reset($items));

        if (\ucfirst($header) === 'Forwarded') {
            foreach (\explode(';', $headerValue) as $headerPart) {
                if (\mb_strtolower(\mb_substr($headerPart, 0, 4)) === 'for=') {
                    $for         = \explode(']', $headerPart);
                    $headerValue = \trim(\mb_substr(\reset($for), 4), " \t\n\r\0\x0B" . '"[]');

                    break;
                }
            }
        }

        return $headerValue;
    }
Find out the client's IP address from the headers available to us.

@param \Psr\Http\Message\ServerRequestInterface $serverRequest
@param string                                   $header        Header name

@return string