Tuesday, April 5, 2011

Re: Override session timeout for a user group

Thanks for the response, after lots of playing around the only way
I've been able to get it to work has been to use cookies

so in the login method I have
$groupId = $this->Authed->user( 'group_id' );
if( $groupId == 2 )
{
$this->Cookie->write( 'extend_session', '1', false, '+7 days' );
}
else
{
$this->Cookie->delete( 'extend_session' );
}

then in config/core.php I have

$extendSession = false;
if( array_key_exists( 'CakeCookie', $_COOKIE ) and
array_key_exists( 'extend_session', $_COOKIE[ 'CakeCookie' ] ) and
$_COOKIE[ 'CakeCookie' ][ 'extend_session' ] == '1' )
{
$extendSession = true;
}

if( $extendSession )
{
// 8 hours for logistics
Configure::write( 'Session.timeout', '288' );
}
elseif( (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad') )
{
// 1 hour for ipad
Configure::write( 'Session.timeout', '36' );
}
else
{
// 15 mins for normal user
Configure::write( 'Session.timeout', '9' );
}

That seems to work ok

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: