Welcome Guest, Not a member yet? Register   Sign In
ion_auth - Is there a way to detected logged in users
#1

[eluser]nnolting[/eluser]
Can anyone tell me if there is a way to detect users that are logged in with ion_auth? I can detect if I am logged in with the
Code:
$this->ion_auth->logged_in()
function but I can't tell if there is any way of knowing what users are currently logged in since logged_in() relies on a user session.
#2

[eluser]cideveloper[/eluser]
Query the auth database.
#3

[eluser]nnolting[/eluser]
[quote author="cideveloper" date="1337186428"]Query the auth database.[/quote]

The only column that I can see useful in that table (users) is 'last_login' but that does not necessary tell anything about who is logged in at a particular moment.
#4

[eluser]jkevinburton[/eluser]
I would change my sessions to database and then query that sessions table for last activity within a 5-15 minute span depending on your personal threshold. I know this could be tricky. I would modify the session library to add a second field 'is_logged_in' - and since the ion_auth library uses sessions, take advantage of this.

May not be the best solution, but i just took it off the top of my head.
#5

[eluser]cideveloper[/eluser]
Are you using DB sessions. If yes, when the user logs in, add some Custom Session Data that matches the session with the users table. I usually add the id, username, and email. Your login code could be something like this

Code:
$username = $this->input->post('username');
$password = $this->input->post('password');
if ($this->ion_auth->login($username, $password)){
$user = $this->ion_auth->user()->row();
$newdata = array(
  'id'  => $user->email,
  'username'  => $user->username,
  'email' => $user->email,
  'logged_in' => TRUE
);

$this->session->set_userdata($newdata);
}


Then if you, the admin wants to see who is logged in you can query the ci_session table and get the info from the user_data field.
#6

[eluser]nnolting[/eluser]
I'll give that a try, I've read about the session storage stuff, but never tried it out, this might be the time.




Theme © iAndrew 2016 - Forum software by © MyBB