Today when I want to create user profile page for my website and want to create system users can manage his active sessions in this system need
- View active sessions Browsers and platform
- See what is current session
- remove unwanted active sessions
How we can do this?
I Find this solutions to save my users
user_id
into session tableYii2 database session - store additional attributes and user information
Logging out specified user, listing who's online by using DB sessions
But there is another problem in implementing this issue: how to classify user sessions based on their browser and platform, and I found this solution.
I added another column to the session database, and inside it, using this class and the code below I saved the browser information and user platform information.
note : you add other data to your session table
But to find the current session, I encountered a problem when I checked
Yii::$app->session->id
and returned the empty string value and I found the solution in the link below.Blank Session ID in Module's BeforeAction
in Yii2-Advanced I create
frontend\components\baseController
and extend all controllers from it and createbeforeAction()
and open session in it something like this:At the end I create ActiveRecord model for session database and use it in profile page to show or remove user sessions