What is the function in PHP to retrieve the URL of the current page?

To retrieve the URL of the current page in PHP, you can use the $_SERVER['REQUEST_URI'] superglobal variable. This variable contains the URI of the current request. By concatenating it with the 'http://' or 'https://' and the $_SERVER['HTTP_HOST'] variable, you can obtain the full URL of the current page.

$currentURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $currentURL;