How can PHP's $_SERVER variable be used to retrieve information about the current URL?

To retrieve information about the current URL using PHP's $_SERVER variable, you can access elements such as $_SERVER['HTTP_HOST'] for the host name, $_SERVER['REQUEST_URI'] for the URI, and $_SERVER['QUERY_STRING'] for the query string. By combining these elements, you can reconstruct the complete URL of the current page.

$current_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo $current_url;