function DrupalKernel::validateHostname

Same name in other branches
  1. 9 core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::validateHostname()
  2. 10 core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::validateHostname()
  3. 11.x core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::validateHostname()

Validates the hostname supplied from the HTTP request.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object

Return value

bool TRUE if the hostname is valid, or FALSE otherwise.

2 calls to DrupalKernel::validateHostname()
DrupalKernel::findSitePath in core/lib/Drupal/Core/DrupalKernel.php
Returns the appropriate site directory for a request.
ValidateHostnameTest::testValidateHostname in core/tests/Drupal/Tests/Core/DrupalKernel/ValidateHostnameTest.php
@covers ::validateHostname @dataProvider providerTestValidateHostname

File

core/lib/Drupal/Core/DrupalKernel.php, line 1535

Class

DrupalKernel
The DrupalKernel class is the core of Drupal itself.

Namespace

Drupal\Core

Code

public static function validateHostname(Request $request) {
    // $request->getHost() can throw an UnexpectedValueException if it
    // detects a bad hostname, but it does not validate the length.
    try {
        $http_host = $request->getHost();
    } catch (\UnexpectedValueException $e) {
        return FALSE;
    }
    if (static::validateHostnameLength($http_host) === FALSE) {
        return FALSE;
    }
    return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.