How to prevent for user logged in twice (to different browser or machines)

In my System user logged in over combobox with cakephp 4.4.11 and db Session and apcu as well.
I try for days to prevent user not to logged in twice at the same time on different systems.
Did somebody got a fine solution or do I have to reinvent the wheel?

Thanks in advanced

I found a solution. Thanks anyway.

Could you share your solution in case it might help others?

Hi all. I can say if somebody got interested and need this, then please contact me, I will answer. Thanks a lot.

sharing is caring… :wink:

You’re right.

  1. Setup database session table. In which user are stored while the are logged in.

in app.php setup this:

'Session' => [
    'defaults' => 'database',
    'cookie' => 'mycookiename',
    'timeout' => 720,
    'cookie_secure'=> true,
    'checkAgent' => false,
    'autoRegenerate' => true,
    'handler' => [
        'engine' => 'ComboSession',
        'model' => 'Sessions',
        'cache' => 'apc'

and in cache add this:

‘apc’ => [
‘engine’ => ‘Apcu’,
‘prefix’ => ‘any_’,

Now after a new user logged in checkout the session table is he/she logged in already?
If so, then add a remark in the the session-table e.g.: loghimout or something.

in your app.php checkout whether user has this remark in his session, if so then log him out.

That means, if a user logged in and then try to login in a other system/browser or something. All previous sessions will be destroyed.

I hope that’s helps you. My problem was in the session data table the data column have had the type blob but it was to short and has been cut. so I change to longblob and that’s it.