![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/amasty/base/Model/ |
<?php /** * @author Amasty Team * @copyright Copyright (c) Amasty (https://www.amasty.com) * @package Magento 2 Base Package */ namespace Amasty\Base\Model; class GetCustomerIp { /** * Local IP address */ public const LOCAL_IP = '127.0.0.1'; /** * @var string[] */ protected $addressPath = [ 'HTTP_X_REAL_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR' ]; /** * @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress */ private $remoteAddress; /** * @var \Magento\Framework\App\RequestInterface */ private $request; /** * GetCustomerIp constructor. * * @param \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress * @param \Magento\Framework\App\RequestInterface $request */ public function __construct( \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress, \Magento\Framework\App\RequestInterface $request ) { $this->remoteAddress = $remoteAddress; $this->request = $request; } /** * @return string */ public function getCurrentIp() { foreach ($this->addressPath as $path) { $ip = $this->request->getServer($path); if ($ip) { if (strpos($ip, ',') !== false) { $addresses = explode(',', $ip); foreach ($addresses as $address) { if (trim($address) !== self::LOCAL_IP) { return trim($address); } } } else { if ($ip !== self::LOCAL_IP) { return $ip; } } } } return $this->remoteAddress->getRemoteAddress(); } }