* IP address of logged in user.
*/
public static function ipAddress($strictIPV4 = TRUE) {
- $address = $_SERVER['REMOTE_ADDR'] ?? NULL;
-
$config = CRM_Core_Config::singleton();
- if ($config->userSystem->is_drupal && function_exists('ip_address')) {
- // drupal function handles the server being behind a proxy securely. We still have legacy ipn methods
- // that reach this point without bootstrapping hence the check that the fn exists
- $address = ip_address();
- }
+ $address = $config->userSystem->ipAddress();
// hack for safari
if ($address == '::1') {
}
}
+ /**
+ * @inheritdoc
+ */
+ public function ipAddress():?string {
+ // Backdrop function handles the server being behind a proxy securely. We
+ // still have legacy ipn methods that reach this point without bootstrapping
+ // hence the check that the fn exists.
+ return function_exists('ip_address') ? ip_address() : ($_SERVER['REMOTE_ADDR'] ?? NULL);
+ }
+
}
return FALSE;
}
+ /**
+ * Get the client's IP address.
+ *
+ * @return string
+ * IP address
+ */
+ public function ipAddress():?string {
+ return $_SERVER['REMOTE_ADDR'] ?? NULL;
+ }
+
}
}
}
+ /**
+ * @inheritdoc
+ */
+ public function ipAddress():?string {
+ // Drupal function handles the server being behind a proxy securely. We
+ // still have legacy ipn methods that reach this point without bootstrapping
+ // hence the check that the fn exists.
+ return function_exists('ip_address') ? ip_address() : ($_SERVER['REMOTE_ADDR'] ?? NULL);
+ }
+
}
return NULL;
}
+ /**
+ * @inheritdoc
+ */
+ public function ipAddress():?string {
+ return class_exists('Drupal') ? \Drupal::request()->getClientIp() : ($_SERVER['REMOTE_ADDR'] ?? NULL);
+ }
+
}