Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Identifying a user....

Quote Reply
Identifying a user....
Okay so....

If a user logs in and selects 'Remember Me' a cookie is set. A user ID can then be found by using the cookie value against $DB->table('gforum_remember')...

If a user logs in and selects 'Don't Use Cookies' a session is appended to the query string. A user ID can then be found by using the session value against $DB->table('gforum_session')...

If a user logs in and selects neither 'Remember Me' or 'Don't Use Cookies' where is the session stored? and, more importantly, how can I find the users ID?


moog
-- I've spent most of my money on beer and women... the rest I just wasted.
Quote Reply
Re: [moog] Identifying a user.... In reply to
Hi,

The session is always stored in gforum_session. If you select use cookies, then the session id is passed via cookie. If that is not checked, then it is passed in the URL. The session though is still in gforum_session table.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Identifying a user.... In reply to
Hi Alex,

Thanks for getting back so soon... here's the problem... this code snippet, in a totally independent script, works fine if I have logged in using the 'Remember Me' OR the 'Don't use cookies' options, however if I log in and select neither option the cookie is not found...

Code:

if (my $cookie = $IN->cookie('forum_hash_remember')) {

$record = $DB->table('gforum_remember')->select( { session_id => $cookie } )->fetchrow_hashref;

} elsif ($input->{session}) { # grabbed from query

$record = $DB->table('gforum_session')->select( { session_id => $input->{session} } )->fetchrow_hashref;
}

my $USER_ID = "$record->{session_user_id}";

$record = $DB->table('gforum_user')->select( { user_id => $USER_ID } )->fetchrow_hashref;

my $USER_NAME = "$record->{user_username}";


Cheers,

Trav.


moog
-- I've spent most of my money on beer and women... the rest I just wasted.
Quote Reply
Re: [moog] Identifying a user.... In reply to
Try:

my $session = $IN->cookie($CFG->{cookie_prefix} . 'session') || $IN->param('session');
my $remember = $IN->cookie('forum_hash_remember');
if ($session) {
$record = $DB->table('session')->select( { session_id => $session })->fetchrow_hashref;
}
elsif ($remember) {
$record = $DB->Table('remember')->select( { session_id => $remember} )->fetchrow_hashref;
}
if ($record) {
$user_id = $record->{session_user_id};
}
else {
# not logged in
}

That needs a bit of tweaking, but I hope you get the idea. Basically you just need to grab the session cookie like you do the remeber cookie. The only tricky part is you need the config object to figure out the name of the session cookie.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Identifying a user.... In reply to
Thanks Alex!

That's the solution I was looking for... I hard coded the $CFG->{cookie_prefix} value and bingo...


moog
-- I've spent most of my money on beer and women... the rest I just wasted.