I'm trying to build an admin interface for site I'm working on and can't seem to figure out how to redirect users first to the login screen (if they haven't logged in yet), then verifying their credentials and redirecting back to the page they initially requested. Should I be storing the requested page in a session variable? I've tried storing $PHP_SELF, but that only seems to return the basename of the script and leaves out the GET values.
For instance, I'm trying to get to www.domain.com/admin/?p=links. (The index script pulls in the HTML for different pages based on the value of $_GET['p']) If the user hasn't logged in yet, it sends them to a login screen and submitting that form needs to validate their credentials and then redirect to /?p=links.