public function Request::getClientIp

Returns the client IP address.

@api

Return value

string The client IP address

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Request.php, line 589

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public function getClientIp() {
  if (self::$trustProxy) {
    if ($this->server
      ->has('HTTP_CLIENT_IP')) {
      return $this->server
        ->get('HTTP_CLIENT_IP');
    }
    elseif ($this->server
      ->has('HTTP_X_FORWARDED_FOR')) {
      $clientIp = explode(',', $this->server
        ->get('HTTP_X_FORWARDED_FOR'));
      foreach ($clientIp as $ipAddress) {
        $cleanIpAddress = trim($ipAddress);
        if (false !== filter_var($cleanIpAddress, FILTER_VALIDATE_IP)) {
          return $cleanIpAddress;
        }
      }
      return '';
    }
  }
  return $this->server
    ->get('REMOTE_ADDR');
}