Fork me on GitHub

Stay Out CakePHP Component

Stay Out CakePHP Component

I have recently been developing a new website which has found me in the position of writing a lot of session handling code. I came across the concept of logged out all sessions across multiple instances, and out came this CakePHP session flushing component stay out.

Stay out works by storing a timestamp in the users session and cross referencing that in the database. The component works by storing a unique SHA1′d string at the time of a user logout action (which should be called manually). When other user sessions of the same user are active and previously a log out has been called, that logged in user is then forced to be logged out.

You can find the project status over at: http://github.com/voidet/stay_out

Usage:

First thing that needs to be done is to include it in your app/controllers/components folder as stay_out.php. Next include it in your list of components, noting that it should come after Auth:

var $components = array('StayOut');

The only thing that you really need to handle is when to execute the logout function. This should be done before you log the user out for example:

function logout() {
	$this->StayOut->setLogout();
	$this->StayOut->logout(); // or $this->Auth->logout();
}

There is another method called StayOut::logout() available to you, however this is just a helpful tool to flush out a user and all cookies associated with them. This is used internally in the event that an older session attempts to use a logged out session, however can also be called as a red alert flush all info helper.

Posted by voidet

Categorised under CakePHP
Bookmark the permalink or leave a trackback.

One Trackback

  1. [...] This post was mentioned on Twitter by Richard S, DevMoose. DevMoose said: Stay Out CakePHP Component: I have recently been developing a new website which has found me in the position of wr… http://bit.ly/9Np8yS [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

or