What I did once was take the data from the table ci_session
where user_data
was different from empty and listed these data, I know it’s not quite what you’re looking for, but I think it should give you a light.
$this->load->model('ci_sessions_model');
$data['all_results'] = $this->ci_sessions_model->get("user_data <> ''");
$this->load->view('widget_sessions', $data);
and in the view I listed the active sessions:
<table>
<thead>
<tr>
<th>IP ADDRESS</th>
<th>USER AGENT</th>
<th>LAST ACTIVITY</th>
<th>USER DATA</th>
</tr>
</thead>
<tbody>
<?php
foreach ($all_results as $all):
$id_user = get_dados_user_data($all->user_data, array('id_user'));
echo "\t\t<tr id='" . $all->session_id . "'>\n";
echo "\t\t\t<td>" . $all->ip_address . "</td>\n";
echo "\t\t\t<td>" . $all->user_agent . "</td>\n";
echo "\t\t\t<td>" . get_timestamp_to_time($all->last_activity) . "</td>\n";
echo "\t\t\t<td>" . get_dados_user_data($all->user_data, array('str_nome', 'str_sobrenome', 'str_email')) . "</td>\n";
echo "\t\t</tr>\n";
endforeach;
?>
</tbody>
</table>
and I have a helper
for the job get_timestamp_to_time
and get_dados_user_data
:
function get_timestamp_to_time($timestamp)
{
if ($timestamp) {
$date = new DateTime();
$date->setTimestamp($timestamp);
return $date->format('d/m/Y H:i:s');
} else {
return NULL;
}
}
function get_dados_user_data($userdata, $valuesReturn = array())
{
if ($userdata) {
$ret = "";
$arUserData = decode_user_data($userdata);
foreach ($arUserData as $key => $value) {
if (in_array($key, $valuesReturn)) {
$ret.= $value . " ";
}
}
return $ret;
}
return NULL;
}
function decode_user_data($userdata)
{
if ($userdata) {
return unserialize($userdata);
}
return NULL;
}
Why not use the Codeigniter library?
– gmsantos
Because I want to take the data straight from the table, turn it into array and make comparisons. It’s not just using the current session, I want to recover old.
– Machado
But in the table you will always have the most current Session of a given client. The other lines refer to other requests. You want to compare the data of different customers, that’s it?
– gmsantos
In fact, of the same, to be able to inform to him, where he is logged.
– Machado