The port name will be appended to the host if it's non-standard.
public getHttpHost ( ) : string | ||
return | string |
use Symfony\Component\HttpFoundation\Request; // Create a new request object $request = Request::createFromGlobals(); // Get the HTTP host name and store it in a variable $host = $request->getHttpHost(); // Output the host name echo "HTTP Host: " . $host;
use Symfony\Component\HttpFoundation\Request; // Create a new request object $request = Request::create('https://example.com/path', 'GET'); // Get the HTTP host name and store it in a variable $host = $request->getHttpHost(); // Output the host name echo "HTTP Host: " . $host;In this example, we create a new Request object manually, specifying the URL and HTTP method. We then retrieve the HTTP host using the getHttpHost() method and output it to the screen. Package library: Symfony/HttpFoundation.
public getHttpHost ( ) : string | ||
return | string |