Welcome Guest, Not a member yet? Register   Sign In
Extending ci_sessions table

I'm currently trying to create a list of 'active users' meaning users that are logged in and have been active in the last few minutes.

Since the session stores the 'last_activity' field in the ci_sessions table I hope to use that.
My problem is, that I can't connect the sessions with the users in an SQL statement since all userdata is stored in a single text field.

Is it possible to extend the ci_sessions table to add a user_id field? Or would there be another way of doing it?

Yes, that is no problem. But given the way the sessions library works, you'll end up replacing it entirely.

And while you're at it, also add a last_updated timestamp. The current timestamp gives the impression that it can be used for that, but it is the last session id rotation timestamp, which could be quite some time ago.

Quote:Note: Session cookies are only updated every five minutes by default to reduce processor load. If you repeatedly reload a page you'll notice that the "last activity" time only updates if five minutes or more has passed since the last time the cookie was written. This time is configurable by changing the $config['time_to_update'] line in your system/config/config.php file.

This is from the manual.

I'm sure someone must have done this before. How is it done in this forum? Is there a free library?

Here's mine.

Go through the code, because it uses a different table layout, and contains other features that you may not need or want.

on the session file you posted - if we wanted to use it - would we replace

or put it in


@cartalot I'd put it in application/libraries (as described at the end of the file). It'll automatically be used.

I'm thinking of extending my users table with a session id column and extending the session class to update this field if the session id changes and the user_id session data is set, but I'm not sure if that could have unforeseen consequences.
Any thoughts?

How did you do this? How does this forum? ("Logged-in Users" in Visitor Statistics at the bottom of this page.

You should not use the session_id in your application, it's an id, random and internal to the session class.

If you need session related data, it should be in the sessions table (either in a separate field or in the userdata). There are several reasons why session_id's change, there is no way you can keep your users table in sync...

Theme © iAndrew 2016 - Forum software by © MyBB