Welcome Guest, Not a member yet? Register   Sign In
Active users ci_session
#1

[eluser]rad11[/eluser]
Hello I have a problem with active people that have a logged_in set to 1 in the column user_data.

Is that method correct?

Code:
public function show_active_users(){
    
    
    $this->db->like('user_data','s:12:"logged_in";i:1;');
    
    $query = $this->db->get('ci_sessions');
    
    
    return $query;
    
}

view
Code:
foreach ($query_active_users->result() as $active_users){
    echo $active_users->ip_address;
}

result is nothing var_dump too nothing say.

#2

[eluser]InsiteFX[/eluser]
The CI session data is serialized and needs to be un-serialized back into an associated array.

Look at the session.php class and you will see how the serialization works.
#3

[eluser]rad11[/eluser]
Ok I do something like this tell me is it good:


View
Code:
<?php


foreach($query_ip->result() as $user):
    $timestamp=$user->last_activity;
    $udata = unserialize($user->user_data);
?>
<tr>

<td>&lt;?php echo $udata['username'];?&gt;</td>

<td>&lt;?php echo gmdate("Y-m-d\ H:i:s\ ", $timestamp);?&gt;</td>

</tr>
&lt;?php
endforeach;
?&gt;

Model
Code:
public function show_active_users(){
  
$this->db
->select()
->where('last_activity >=', 'UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 10 MINUTE))')
->like('user_data', 's:12:"is_logged_in";i:1;');

$query = $this->db->get('ci_sessions');
return $query;
}




Theme © iAndrew 2016 - Forum software by © MyBB