0

I am using Codeigniter's Session class to store session values in the database. Contained within the userdata field is the user's username and other values.

I want to get the username from each userdata field where the lastactivity is >= let's say 5 minutes.

The only way I can think to accomplish this is:

  • search for users active in last 5 minutes
  • get the userdata for each row returned
  • unserialise userdata
  • extract username

However this seems like the long way. Is there a cleaner/better way to do this?

2
  • Do u want to store all username etc. data from your database whose lastactivity > x to CI Session ? Commented Feb 16, 2013 at 6:10
  • The userdata field in the DB will contain a few different values, I just need to extract one of those. Commented Feb 16, 2013 at 6:20

1 Answer 1

1

Try this code.

$query = $this->db->select('user_data')->get('ci_sessions');

$user = array(); /* array to store the user data we fetch */

foreach ($query->result() as $row)
{
    $udata = unserialize($row->user_data);

    /* put data in array using username as key */
    $user[$udata['user_name']] = $udata['user_role']; 
}

from the result array, u can fetch needed information.

Sign up to request clarification or add additional context in comments.

1 Comment

That's identical to the solution I listed and said I was trying to avoid if possible. I realise it may be necessary but only as a last resort.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.