protected function _getIp() {
    $ip = null;
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
      $ip = $_SERVER['HTTP_CLIENT_IP'];
    } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
      $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else if (!empty($_SERVER['REMOTE_ADDR'])) {
      $ip = $_SERVER['REMOTE_ADDR'];
    }

		if ($this->_isValidIpv4($ip)) {
			return $ip;
		}

		// sometimes the value is multiple IPs separated by commas
		// (when there are multiple proxies, for example)
		$ips = explode(',', $ip, 2);
		$ip = trim($ips[0]);
		if ($this->_isValidIpv4($ip)) {
			return $ip;
		}

    return null;
  }