How do u get the host name e.g http://localhost/xxx/ or http://www.xxx.com/
$_SERVER['HTTP_REFERER']
Also in $_SERVER there's HTTP_HOST or SERVER_NAME might also be good for ya.
If you shove phpinfo() in a page it'll list all that guff for you.