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.

Yeh


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.
Kristi
Kristi

137

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

Harper
Harper

5

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`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Created: 27 Sep '16

Last Reply: 28 Sep '16

Replies: 3

Views: 575

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