How can you retrieve the full domain name with the HTTP or HTTPS protocol using PHP?

To retrieve the full domain name with the HTTP or HTTPS protocol in PHP, you can use the $_SERVER superglobal array. The $_SERVER['HTTP_HOST'] variable will give you the domain name, and the $_SERVER['HTTPS'] variable will indicate whether the request was made using HTTPS or not.

$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https://" : "http://";
$domain = $_SERVER['HTTP_HOST'];

$fullDomain = $protocol . $domain;

echo $fullDomain;