diff --git a/src/Pattern/geolocatorAbstract.php b/src/Pattern/geolocatorAbstract.php index da5a97b..f09a9fd 100644 --- a/src/Pattern/geolocatorAbstract.php +++ b/src/Pattern/geolocatorAbstract.php @@ -203,23 +203,23 @@ protected function getRealIp( ): ?string { // https://api.ipify.org?format=json - $api = "https://api.ipify.org?format=json"; - // todo: problem in same cas to get real ip !!! - $data = $this->senApi( $api ); - $ip = json_decode($data, false, 512, JSON_THROW_ON_ERROR); - return $ip->ip; -// // in dev mode mock -// if ( $this->kernel->getEnvironment() === 'dev') { -// // for test Bulgary "156.146.55.226" -// return $this->neoxBag->getIpLocalDev() ; -// } -// -// $request = $this->requestStack->getCurrentRequest(); -// $ip = $request->getClientIp(); -// -// if ($request->headers->has('X-Real-IP')) { -// return $request->headers->get('X-Real-IP'); -// } +// $api = "https://api.ipify.org?format=json"; +// // todo: problem in same cas to get real ip !!! +// $data = $this->senApi( $api ); +// $ip = json_decode($data, false, 512, JSON_THROW_ON_ERROR); +// return $ip->ip; + // in dev mode mock + if ( $this->kernel->getEnvironment() === 'dev') { + // for test Bulgary "156.146.55.226" + return $this->neoxBag->getIpLocalDev() ; + } + + $request = $this->requestStack->getCurrentRequest(); + $ip = $request->getClientIp(); + + if ($request->headers->has('x-real-ip')) { + return $request->headers->get('x-real-ip'); + } // // if ($request->headers->has('CF-Connecting-IP')) { // $ip = $request->headers->get('CF-Connecting-IP'); @@ -229,8 +229,8 @@ protected function getRealIp( ): ?string // $ips = explode(',', $request->headers->get('X-Forwarded-For'), 2); // $ip = trim($ips[0]); // The left-most IP address is the original client // } -// -// return $ip; + + return $ip; } private function stringContainsSubstringFromArray(string $mainString, array $substringsArray): bool