Page 1 of 1

User has to login, but once logged in...

Posted: Wed Apr 26, 2006 10:26 am
by seodevhead
I have a members-only area on my web application where users have to login. Unregistered visitors will often try to access a "members-only" area and are presented with the message stating:

"You must first Login to access this area. Click here to login."

Once they go to the login page and login, how do I go about redirecting them back to the section they were at when they got the "restricted access -> go login" message like the one above? I would like for the login page to know where they had come from in my site and send them back to it after logging them in? Any ideas? Thanks!

Posted: Wed Apr 26, 2006 10:29 am
by shiznatix
if they are not logged in and try to view a restricted page then, using the $_SERVER array, set the page they are at into a session, redirect them to whatever, then when they login redirect to the site they where trying to goto from the $_SESSION and unset that $_SESSION var.

yes?

Posted: Wed Apr 26, 2006 10:29 am
by feyd
The script knows where it is when the "go login" message is shown. Store that information somewhere or pass it via the URL in some fashion to the login script. The login script can then, upon successful login redirect back to the URL referenced.

Posted: Wed Apr 26, 2006 10:33 am
by seodevhead
Thanks a lot guys... I got the jist now!!! :) Going to go implement!