Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Request.php

function Request::getPort

Returns the port on which the request is made.

This method can read the client port from the "X-Forwarded-Port" header when trusted proxies were set via "setTrustedProxies()".

The "X-Forwarded-Port" header must contain the client port.

Return value

int|string|null Can be a string if fetched from the server bag

1 call to Request::getPort()
Request::getHttpHost in vendor/symfony/http-foundation/Request.php
Returns the HTTP host being requested.

File

vendor/symfony/http-foundation/Request.php, line 869

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public function getPort() : int|string|null {
    if ($this->isFromTrustedProxy() && ($host = $this->getTrustedValues(self::HEADER_X_FORWARDED_PORT))) {
        $host = $host[0];
    }
    elseif ($this->isFromTrustedProxy() && ($host = $this->getTrustedValues(self::HEADER_X_FORWARDED_HOST))) {
        $host = $host[0];
    }
    elseif (!($host = $this->headers
        ->get('HOST'))) {
        return $this->server
            ->get('SERVER_PORT');
    }
    if ('[' === $host[0]) {
        $pos = strpos($host, ':', strrpos($host, ']'));
    }
    else {
        $pos = strrpos($host, ':');
    }
    if (false !== $pos && ($port = substr($host, $pos + 1))) {
        return (int) $port;
    }
    return 'https' === $this->getScheme() ? 443 : 80;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal