Storing session id with a user

Hello,

I store sessions in my database and I'd like to store a session_id
with a user when they log in. How do I determine what a user's session
id is?

The reason I want to do this is because I'd like to display users currently logged in.

If I can link a session to a user in my database, then I can check the updated_at column
in the sessions table and determine who is active.

Is this the correct way to go about doing this?

thanks in advance,
Chris.

Chris H wrote:

Hello,

I store sessions in my database and I'd like to store a session_id
with a user when they log in. How do I determine what a user's session
id is?

session.session_id

The reason I want to do this is because I'd like to display users
currently logged in.

session.session_id won't help here as it applies to the current user only.

If I can link a session to a user in my database, then I can check the
updated_at column
in the sessions table and determine who is active.

Is this the correct way to go about doing this?

There was a similar discussion about this previously. Basically you already
have access to the user session in the AR Store. You just need a way to
differentiate a user session from anonymous ones, if you have both session
types.

It might be possible to add a user_id column to the AR Store table and
populate the column when a user logs in. Alternatively, record users in a
separate user_table. You will have more flexibility in storing and managing
user info with this approach.

HTH,

Long
www.edgesoft.ca/blog/read/2 - rails articles

Hi Chris,

Chris H wrote:

How do I determine what a user's session id is?

If I can link a session to a user in my database, then
I can check the updated_at column in the sessions
table and determine who is active.

session[:id] will give you the id of the current session, but I don't think that's what you'll end up wanting.

hth,
Bill

take a look at this for some info:

http://habtm.com/articles/2005/12/15/whos-online