What is the purpose of using $_SERVER['HTTP_HOST'] in PHP and how can it be utilized to extract information from the address bar?

When using $_SERVER['HTTP_HOST'] in PHP, the purpose is to retrieve the host name of the server where the current script is executing. This can be useful for various tasks such as building dynamic URLs, determining the domain name for setting cookies, or validating the domain name of incoming requests. To extract information from the address bar, you can combine $_SERVER['HTTP_HOST'] with other server variables like $_SERVER['REQUEST_URI'] to get the full URL.

// Get the full URL of the current page
$fullURL = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

// Extract specific information from the address bar
$parts = parse_url($fullURL);
$domain = $parts['host'];
$path = $parts['path'];
$queryString = $parts['query'];

echo "Domain: $domain<br>";
echo "Path: $path<br>";
echo "Query String: $queryString<br>";