Why not change your authentication to happen in an object which is called at the beginning of any page?
PHPLIB uses an auth object which will die() in the script if the user isn't logged in but will not change the url the user is trying to access.
While $HTTP_REFERER (check spellin') is what you are asking for, my solution is a lot easier to maintain.
Tom