I have been trying to do exactly this.. checking for authentication and if not logged in it shoots them to a login form.. when they authenticate through the login form it shoots them back to where they came from...
Either a switch or an if, if else situation works on the secure page.. when they shoot over to the login page I send a variable through the header that will match a case in a switch statement that will allow them to view the login form, and register a variable via Session_register() that gets set to the relative path on the url of the page they came from.. when they submit their information on the log in page and it makes it passed the authentication, SQL Query, etc... and if everything checks out I set the header to go back to the page they came from via a variable sent from the original page..
the trick is not having any breaks in the PHP page of code and echoing nothing out before sending the header.. as soon as something is echoed out the page automatically loads the header.. so by sending nothing out and only checking the login and password, when it clears the first thing that the browser reads is the header.. if it does not check out a warning is echoed and they must re-submit.. I also check the session variables to make sure that they match when going back to the secure page.