redirect to specific areas upon member login

greg's picture

He has: 1,581 posts

Joined: Nov 2005

On my site in all the member only areas I have a header page (included in ALL pages) which firstly checks if user is logged in, if not it displays a login form

if they fill in the form, the login script checks their login details they input with the DB, then if correct takes them to their personal member page
(if not correct tells them wrong info - try again)

BUT
what if a member is logged in, and is reading a member only area and he/she bookmarks it...
when they come back later and use that bookmark, the script on the page they bookmarked determines they are not logged in and takes them to login page

then successful login takes them to their member homepage, not the bookmarked page!
(or they may even type in a full adress of a members area page they remembered - same problem)

What makes this tricky (at least for me) is I need a clause where if they didnt use a bookmark to a memebrs area (or type in an address to members area) then they came from the non-members area
this includes the contacts page, about us and various other pages that aren't member specific they could be reading then decide to login

so on those occasions, they need to simply be sent to the their members hompage.

I know
$_SERVER['HTTP_REFERER']

but dont see how it could be used in this situation, as if they where reading say for example "contact.php" upon login it will take them back there
which is bad, as they should be taken to the members homepage -
I determined no one will be reading the about us or contact page and then decide to log in and then continue reading that page? why would they?
so taken to the members homepage is what 99.9% of users will be wanting upon deciding to login

So is there any tricks with the bookmarks?
All the members specific stuff is in a seperate folder /members/
So are there any tricks with $_SERVER['HTTP_REFERER'] whereby I can make IF ELSE clauses for specific folders?

Confused

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

In your redirect to the login page, do something like this:

<?php
header
('Location: login.php&r=' . urlencode($_SERVER['REQUEST_URI']));
?>

That passes the page that the user tried to access before logging in. Then, after you check the login, do something like this.

<?php
if (isset($_GET['r']))
{
   
header(\"Location: http://www.domain.com/\" . $_GET['r']);
    exit();
}
else
{
    header(\"Location: http://www.domain.com/myaccountorsomething\");
    exit();
}
?>

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.