[eluser]exodus7[/eluser]
Steve,
I'm sure there are other ways of doing this, but the way I do it goes like this:
In my login function, if the username & password are correct, I do the following:
Code:
$data['query'] = $this->loginmodel->curUser('users');
$newdata = array(
'isLOGGED' => 'YES',
'curUser' => $data['query']->username,
'curUserId' => $data['query']->id
);
$this->session->set_userdata($newdata);
So what that does is - it pulls up the record of the person who logged in and stores the username and ID of the user in a session which I can retrieve (as long as the session has not expired) anytime I need using: $this->session->userdata('curUserId');
I use the 'isLOGGED' value to determine if they are currently logged in to preform a specific task like posting a message or updating a record.
You can easily add a column or two in your users table to include the date of the last login or keep track of any other statistic like user rights and then store that in the session if needed...
It might/might not be the best way of doing it, but it works.
Does anyone know of an easier way?