Сессии php и десериализация

Задача, проход по списку сессий, сессия стандартно в файлах, получить доступ к данным.
<div id="usersmonitor" >
<table id="usersmonitortable" class="table table-bordered table-hover table-condensed table-fixed">
<thead>
<tr><th style="width: 15%;">Последняя активность</th><th style="width: 35%;">ФИО</th><th style="width: 25%;">e-mail</th><th style="width: 25%;">Роль</th></tr>
</thead>
<tbody>
<?php 
function unserialize_php($session_data) {
        $return_data = array();
        $offset = 0;
        while ($offset < strlen($session_data)) {
            if (!strstr(substr($session_data, $offset), "|")) {
                throw new Exception("invalid data, remaining: " . substr($session_data, $offset));
            }
            $pos = strpos($session_data, "|", $offset);
            $num = $pos - $offset;
            $varname = substr($session_data, $offset, $num);
            $offset += $num + 1;
            $data = unserialize(substr($session_data, $offset));
            $return_data[$varname] = $data;
            $offset += strlen(serialize($data));
        }
	return $return_data;
}

$directory = session_save_path().'/';
$filenames = array();
$iterator = new DirectoryIterator($directory);
foreach ($iterator as $fileinfo) {
    if ($fileinfo->isFile()) {
        $filenames[$fileinfo->getMTime()] = $fileinfo->getFilename();
    }
}
krsort($filenames);

foreach($filenames as $mt => $fn) {
 $ot = new \DateTime();
 $ot->setTimestamp($mt);
 $st = $ot->format('d.m.Y H:i');
 $t = unserialize_php(file_get_contents($directory . $fn));
 if (isset($t['auth']) && isset($t['auth']['user'])) {
	$tt = (object)$t['auth']['user'];
	echo "<tr><td>{$st}</td><td>{$tt->nameLast} {$tt->nameFirst} {$tt->nameMidle}</td><td>{$tt->email}</td><td>{$tt->name}</td></tr>";
 }
}

?>
</tbody>
</table>
</div>

<script>
$(function () {
	setInterval( function() {$('#usersmonitor').load('/users/usersmonitor #usersmonitortable', {act: 'refresh'})} , 30100 );
});
</script>

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *