Another quick snippet that might save you some time. Recently, while working on a client site, I discovered that Magento wouldn’t obey the session timeout that I set for the Admin panel. I changed the database value, went spelunking in the code, and came up with nothing. Turns out, the fix for my problem wasn’t in Magento at all.
Session cookies in Magento are timed, but this means that they obey different rules than other systems that just keep permanent session cookies. Specifically, they obey PHP’s rules about maximum session length. Take a look inside your php.ini file and find the following line:
; After this number of seconds, stored data will be seen as 'garbage' and ; cleaned up by the garbage collection process. ; http://php.net/session.gc-maxlifetime session.gc_maxlifetime = 1440
Your Magento session will never last longer than that length of time. As you can see, mine was set to 1440 seconds, or 24 minutes, which isn’t nearly enough time. I want to stay logged in for an entire day, so I decided to change this value. I could have changed it in php.ini, but that’s not a very clean solution, and it would affect all my sites, so instead I edited .htaccess in my Magento folder and added:
#resetting the max cookie lifetime to one day to allow # long sessions php_value session.gc_maxlifetime 86400
After restarting Apache, Magento worked as expected and I am now able to stay logged in for an entire day. Hope that helps!
Changing the Admin Session length in the Backend
Just go to System -> Configuration -> General > Web. Click “Session Cookie management” tab & adjust the value for “Cookie Lifetime”. And voila! You’re all set! There is however a small complication with this method.
This works perfectly as long as PHP’s max lifetime is set *above* the threshhold you set in the admin panel. Unfortunately, on many PHP installations, this number is 15 minutes, so you may have mixed results. The reason for this is that Magento uses cookies with expiry times, rather than true “session cookies”, which means that the cookies obey PHP’s built in cookie lifetime settings.
The post Setting Your Magento Admin Session Length appeared first on Coding Basics.