How can _SERVER variables be used to retrieve the current page URL in PHP?

To retrieve the current page URL in PHP, you can use the $_SERVER['REQUEST_URI'] variable. This variable contains the URI of the current page, including query parameters if any. By accessing this variable, you can easily get the current page URL in your PHP script.

$currentURL = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $currentURL;