I'm new to this but had a similar query that I solved through looking for the environmental variables that my server supports.
I found http://www.zytrax.com/tech/web/env_var.htm very useful for apache servers, read through it all (not long) and you may find several useful variables.
I think you would just need $QUERY_STRING to return the entire string then prepend the host and page to that string, if the host and page can differ then you can get those from the environment variables too, just dont use HTTP Header info as it may not be accurate.
Good luck,
Gary.
P.S. I'm seeking an answer to max script size in PHP and best way to code large scripts, please see http://www.phpbuilder.com/board/showthread.php?s=&threadid=10253335 if you can help.