Category: Authentication

Q: How to prevent multiple logins on same browser/computer in Cakephp?

I just finished my work on registration and login of my latest Cakephp application (Auth Component). Does anyone knows how to prevent multiple logins on the same browser or computer in Cakephp 3? I have no idea to start with.

Please help, thanks.


3 Answers

Version: 3

Just a thought:

  1. Add a field in Users' table to store session_id.
  2. [on login] Get the previous session_id that stored in Users' table for this user.
  3. Be sure to destory the previous session_id. 
  4. [on login success] Start a new session with id and save the new session_id to database. This will overwrite session_id and force to logout the previous session connection for this user.


You can use OpenID or Pubcookie to manage all authorized sessions to your application. 



I would store a user_id field in sessions when they login so I can track user is online or not. Also you have to destroy session on user logout.

CREATE TABLE `sessions` (
  `id` varchar(255) CHARACTER SET utf8 NOT NULL,
  `data` text,
  `expires` int(11) DEFAULT NULL,
  `created` datetime NOT NULL,
  `user_id` int(11) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`)

Created: 27 Sep '16

Last Reply: 28 Sep '16

Replies: 3

Views: 3571

Votes: 0

Welcome to Aero Coding!

Aero Coding is a CakePHP-focused Q&A community for professional and enthusiast cake bakers. It's built and run by you as part of the community.

Join Now Tour

Download Cakephp

Start baking your own CakePHP application!

Cakephp All Versions