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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

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

Post 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!
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post by seodevhead »

Thanks a lot guys... I got the jist now!!! :) Going to go implement!
Post Reply