How to Change Session timeout or Session Length in CakePHP

Hello Friends, This is my first ever blog. I am web developer having 7 plus year of experience in PHP,Ajax, jQuery, HTML, Kohana, CakePHP, WordPress, Joomla, Opencart. I as a developer face a lot of issues for which I usually search for such blogs and posts which can help me find out those answers. This post will help you change session length or Session timeout length  in Cake PHP.

CakePHP Session timeout

Due to CakePHP high security nature it automatically logs out user or automatically destroy all sessions. If Security Level is High then session timeout is low. So by default CakePHP is giving high level security. It means in CakePHP Security Level and Session Timeout both are relative to each other. So if you want to change Security Level and Session Timeout in CakePHP then follow steps shown below :

1. Open core.php file exists in “cakePHP/app/config/” or “app/config” dierctory.

2. Find “Security.level“ and “Session.timeout“in core.php.

3. You will see “Security.level” is by default set to “High“.

4. Now below i am explaining you what is meaning of “Security.level” set to “High” and also how it is related to “Session.timeout“.

CakePHP counts “Session.timeout” Regarding to “Security.level“, means for example if you set “Security.level” to “medium” then cakePHP will multiply a figure (100 for medium, fix for all security level) to “Session.timeout“. Means if you set “Security.level” to “medium” and “Session.timeout” to 100 , So session timeout will be 100(for medium security level) x 100 (session timeout) = 10000 seconds.

this is how it calculates the timeout period:

‘high’ – Session timeout in ‘Session.timeout’ x 10

‘medium’ – Session timeout in ‘Session.timeout’ x 100

‘low’ – Session timeout in ‘Session.timeout’ x 300

So if “Security.level” is high then it will multiply “Session.timeout” with 10.

if “Security.level” is medium then it will multiply “Session.timeout” with 100.

if “Security.level” is low then it will multiply “Session.timeout” with 300.

So if you want to change session timeout or increase session timeout for cakePHP application then you must change “Security.level” and “Session.timeout” variables in core.php.

This should solve your CakePHP session timeout issue.

“I am PHP Freelancer having more than 7 years of experience, if you want to do any project with me then you can contact me.”

Be Social, Share!
    • Ramesh

      Great post…