User only uses one device for user logged in

I’m write the code for Only user uses one device and force closing from another devices in simultaneous use!!
Unfortunately, I have a problem. User session in “cscart_sessions” table of the db is ENCODED and “data” column type blob, and can not get sessions by user_id!
function …

return db_get_field(‘SELECT COUNT(*) FROM cscart_sessions WHERE decode(session_id) = ?i’, $user_id);


return db_get_field(‘SELECT COUNT(*) FROM cscart_sessions WHERE data LIKE ?l’, $user_id);

Can you guide me in this matter?
How to get sessions of user with function?
For example:

// code


Please share your knowledge. Thanks you so much


There is no direct way to retrieve session data for a user with a specific user_id. Session data is stored in the PHP serialize format and is unserialized by the standard PHP mechanisms. Please see the following article on for details on working with sessions:
PHP: session_set_save_handler - Manual

You may need to use your own read/write session handlers and store the user_id associated with the session if you want to be able to retrieve all the session data associated with the particular user_id.

You can check how these methods are implemented in the default CS-Cart session mechanism, in the Tygh\Web\Session class (app/Tygh/Web/Session.php).

It’s true! and course hard
If I want the user to automatically logout of other devices after logging in, is there a simple way?


I can recommend you to update the password_change_timestamp column of the cscart_users table and in the Tygh::$app['session']['auth']['password_change_timestamp'] of that one specific session, set up the same value.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.