CakePHP 2.8.x: Storing Sessions in the Database Revisited


A while back in January 2013, I wrote an article on how to store CakePHP’s sessions in the database, instead of using PHP as the session handler. Recently I received a question if it would be possible to expire (delete) all of a user’s sessions except the current one. It made me look back at the code I wrote in 2013 and I wondered if I could do better than I did before.


In this article, I cover how to setup CakePHP 2.8.x (the version is important, because of a bug fix that was necessary to make it work!) to use sessions stored in the database. I answer the question if it is possible to delete a user’s old sessions except the current one too. I also include an updated version of my previous attempt of retrieving online users. I placed all the code used on github for easy viewing.

“CakePHP 2.8.x: Storing Sessions in the Database Revisited” verder lezen