I need help figuring out how to allow users who login go back to the page that they were on before being sent to the login page. Here is a quote from my boss:
Sometimes I forget to sign in and I go to a page, click and get the notice about joining or signing in. That is fine, but is there a way, once I sign in to open the page I was trying to open prior to signing in, instead of having to go through all the navigation again?
I'm using PHP to do this project.
Whatever mechanism forwards the user to the sign-in page should include the original page's URL as a parameter. Something like:
Then the
login.php
page can redirect to that page after the user authenticates:You may want to put in some checking on the
redirectTo
value inlogin.php
to make sure nobody's trying to do anything malicious, I suppose. Though I can't currently think of anything malicious they could do. (Though you would want to include a default if no URL was provided.)But the general idea is that the authentication mechanism provides the login page with a redirect URL when it detects that the user needs to login.