yii2-cookbook
yii2-cookbook copied to clipboard
Logging out specified user, listing who's online by using DB sessions
See https://github.com/yiisoft/yii2/issues/10404.
Could be solved by using DB sessions and writing additional info into the table:
'session' => [
'class' => 'yii\web\DbSession',
'writeCallback' => function ($session) {
return [
'user_id' => Yii::$app->user->id,
'last_write' => time(),
];
},
],
Then it's easy to work with it via SQL:
-- Kill user sessions. You need to invalidate user cookie as well (change)
DELETE FROM session WHERE user_id = :user_id;
-- Need to change auth key in user table afterwards else "remember me" cookie won't be invalidated.
-- Get all users active in recent hour
SELECT user_id FROM session WHERE last_write - 3600 < :now;
http://stackoverflow.com/questions/34207606/yii2-logout-spesific-user/34207850#34207850
http://yiiframework.ru/forum/viewtopic.php?f=4&t=7486
In my case It began from https://github.com/yiisoft/yii2/issues/9718
what about the same functional with yii\redis\Session? How I can count authorized users?
@Senegal to some like this https://github.com/bscheshirwork/yii2-redis-session