There was a problem with one of the script I'd posted (I think we actually found a different way altogether of doing it) but it was an issue with $PHP_SELF when used in a file that gets included – it ends up showing the name of the INCLUDED file (not the current url).
Just for my future reference, I just tried this instead of PHP_SELF and it seemed to work ok with includes.
"http://".$_SERVER['HTTP_HOST'].$_SERVER['PATH_INFO']
Alternatively – if there's a "query string" at the end of the current url that you want to grab as well (ie http://www.domain.com/test.php?variable=value) you can add this onto the end of the line above:
.$_SERVER['QUERY_STRING']
(side note the . is just used to concatenate the different parts)