1 bootstrap.inc backdrop_check_trusted_hosts($host)

Checks if a host matches the trusted host patterns in settings.php.

@since Backdrop 1.14.0


string $host: The host to check against the patterns specified in settings.php.

Return value

TRUE if the host can be trusted; FALSE otherwise.:


core/includes/bootstrap.inc, line 4397
Functions that need to be loaded on every Backdrop request.


function backdrop_check_trusted_hosts($host) {
  $trusted_hosts = &backdrop_static(__FUNCTION__, array());
  $trusted_host_patterns = settings_get('trusted_host_patterns', array());

  if (PHP_SAPI !== 'cli' && !empty($trusted_host_patterns)) {

    if (in_array($host, $trusted_hosts)) {
      return $host;

    foreach ($trusted_host_patterns as $pattern) {
      $pattern = sprintf('{%s}i', str_replace('}', '\\}', $pattern));
      if (preg_match($pattern, $host)) {
        $trusted_hosts[] = $host;
        return TRUE;

    return FALSE;

  return TRUE;