You merely need the environment variables exposed by the web server. They contain all the information you need to construct an appropriate URL, and append the additional information to it. Also, you might be interested in visiting
PhpMonks for similar questions. ;)