Ion Auth , Get all current logged in users logged
-
02-07-2021 - |
Question
I'm using ion auth library with codeigniter. I can get all members on ceratin group but can't get all logged_in users in that group. Does anyone know how can i achieve this? Thank you all
Ok im edditing this because i found a way of doing it... I ve passed my session for database , table ci_sessions, and now i can see the users logged on based on table number of rows.
i found another problem.
I'm unserializing user_data of ci_sessions this way
$query = $this->db->get('ci_sessions'); foreach ($query->result() as $row) { var_dump([$row->user_data]); $user_data = unserialize($row->user_data); var_dump($user_data); }
and i get user_data as an array like this
array (size=6) 'user_data' => string '' (length=0) 'identity' => string 'joao.costa@onegreat.org' (length=23) 'username' => string 'joao.costa' (length=10) 'email' => string 'joao.costa@onegreat.org' (length=23) 'user_id' => string '14' (length=2) 'old_last_login' => string '1347619173' (length=10)
i can't now get my user_id cause it says user_id is a string nd the 14 too.
what am i doing wrong?
i tried doing something like this
user_data->user_id
thank you all
Solution
Why are you unserialising the array? There is no need.
$query = $this->db->get('ci_sessions');
foreach ($query->result() as $row)
{
var_dump([$row->user_data]);
$user_data = $row->user_data;
var_dump($user_data);
// or
var_dump($user_data->user_id);
}
OTHER TIPS
To access the elements in the array, use array notation:
user_data['user_id']