Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8295243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:31:08+00:00 2026-06-08T14:31:08+00:00

Im Using CakePHP 2.2.1 and im trying to improve my User Authentication with the

  • 0

Im Using CakePHP 2.2.1 and im trying to improve my User Authentication with the Auth Component. When Users try to log in from multiple locations they get individual session IDs, what i want to do is kill the old session so the user cannot log in from multiple locations at the same time.

I converted how CakePHP saves its sessions using this post cakephp prevent user login from multiple locations at the same time but no answer was given on how to kill off the old session when the new one is created.

I thought about creating a Session Model and using that to select the records but im not sure if thats a safe route to go with.

I also read through the CakePHP documentation on the Session Component and CakeSession Datasource hoping there might be a hint but i wasnt able to find anything.

Any advice would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:31:10+00:00Added an answer on June 8, 2026 at 2:31 pm

    Generally, you want to switch Session handling to Database, so you can delete stale sessions when you detect the same user logs in with a different session_id.

    The steps, to give you an idea:

    1. Switch Session handling to Database

      Configure::write('Session.save', 'database');
      
    2. Create cake_sessions table

      cd app         
      Console/cake schema create Sessions
      

      You would then see the following:

      Cake Schema Shell
      ---------------------------------------------------------------
      
      The following table(s) will be dropped.
      cake_sessions
      Are you sure you want to drop the table(s)? (y/n) 
      [n] > y
      Dropping table(s).
      cake_sessions updated.
      
      The following table(s) will be created.
      cake_sessions
      Are you sure you want to create the table(s)? (y/n) 
      [y] > y
      Creating table(s).
      cake_sessions updated.
      End create.
      
    3. Assuming you bind session_id to user_id by

      $this->Session->write('user_id', 123456);
      
    4. Iterate through data field at your session database and delete the row off if the same user_id enters your site and with a different session_id.

      Unfortunately, CakePHP stores data as serialize()-ed data. You will have to either iterate through each of the rows at cake_sessions table to look for matching user_id contained in seralized data to delete.

      Or, just to give you an idea, you can use the following SQL for an approximate method to delete the associated row:

      DELETE FROM `cake_sessions` WHERE `cake_sessions`.`data` LIKE '%123456%';
      
    5. That way the old user who has the old session_id will not be able to continue on the site as the logged in user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send an e-mail from a cron using CakePHP shell but
I'm trying to create an XML sitemap using CakePHP, from a table which has
I am trying to send mail using CakePHP in-built Email component. When I send
I am using cakephp. I am trying get data from facebook using file_get_contents. I
I am using cakephp and trying to pass an array from the view to
I am using cakePHP and I am trying to get the paginator component to
I'm trying to migrate my app from cakephp 2.0 to 2.1. I've been using
I'm currently trying to change my cakephp login from using the username field to
I'm using cakephp and trying to check if a table has data entered in
I am using cakephp 2.1 and i am trying to upload files and how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.