The port name will be appended to the host if it's non-standard.
public static getHttpHost ( ) : string | ||
return | string |
$url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; echo $url;
if ($_SERVER['HTTP_HOST'] == 'example.com') { header('Location: https://www.example.com'); exit; }This code checks the current HTTP host and redirects to a different URL if the domain "example.com" is used without "www". This is a common practice to ensure that all traffic uses a consistent URL format. The getHttpHost() function is part of the PHP built-in server and does not require any external package or library.
public static getHttpHost ( ) : string | ||
return | string |