Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging out specified user, listing who's online by using DB sessions #92

Open
samdark opened this issue Dec 16, 2015 · 5 comments
Open

Comments

@samdark
Copy link
Owner

samdark commented Dec 16, 2015

See yiisoft/yii2#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;
@SilverFire
Copy link
Contributor

@samdark
Copy link
Owner Author

samdark commented Dec 16, 2015

@ElisDN
Copy link

ElisDN commented Dec 16, 2015

In my case It began from yiisoft/yii2#9718

@Senegal
Copy link

Senegal commented Mar 31, 2017

what about the same functional with yii\redis\Session? How I can count authorized users?

@bscheshirwork
Copy link

@Senegal to some like this https://github.com/bscheshirwork/yii2-redis-session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants