What are some alternative approaches to retrieving the current URL in a PHP script when traditional methods like $_SERVER['SCRIPT_URI'] do not work in a frameset environment?

In a frameset environment, traditional methods like $_SERVER['SCRIPT_URI'] may not accurately retrieve the current URL of a PHP script due to the way frames work. One alternative approach is to use a combination of different server variables like $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'], and checking if the script is being accessed over HTTPS using $_SERVER['HTTPS']. By combining these variables, you can construct the current URL dynamically in a frameset environment.

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