I'm building a login system and I'm doing some validation on it. All functional except, the verification if user is already logged in.
I'm using the method below, but it's not 100% functional. What I want to do is check if the user trying to login is already logged in to some session.
What I want is to prevent a single user from having two sessions.
Method Code:
private function _valida_usuario_logado()
{
$id = $this->session->userdata('id');
$ci_sessions = $this->auditoria->listar_ci_sessions();//$this->db->get('tbl_ci_sessions');
foreach($ci_sessions->result() as $item)
{
$user_data = $item->user_data;
$sessions = unserialize($user_data);
$id_logado = $sessions['id'];
}
if ($id == $id_logado)
{
echo 'ja_logado';
exit();
}
else
{
echo 'nao_logado';
exit();
}
}