0

I am new to Magento and I want to destroy the session when

  1. the user doesn't browse through your site for a while (5 mins) and
  2. the user closes the browser directly

In both cases the session should expire and redirect to login page. I Googled for this and I found that:

System->Configuration->Web->Session Cookie management->Cookie Lifetime

  1. If I will set this value to 300(5 mins) then the session will expire and it's fine.
  2. If I set the same value to '0' then it will work for second case(if browser close then session expire)

Suppose I want to expire session for above both cases then how can I get it work?

  • And will probably break in IE if less than 3600 seconds. Actually, one of the issues that will get you later on is that Magento will redirect weirdly in the cart for IE if set to less than one day. It's a local browser / server time mismatch issue that the Magento/IE combination develops indigestion over. – Fiasco Labs Aug 30 '14 at 16:55
1

I've thought about this previously, and while I haven't written any code, I suppose it might look something like:

Set the cookie lifetime to 0. Then you have a javascript solution to detect an idle user, or whatever you want to use to determine how your five minutes is determined.

The reason for doing it this way instead of in reverse (ie. setting cookie to 300 and then using javascript to detect browser close) is that javascript has some limitations here while detecting an idle user on a page is less limited.

  • Thanks pspahn, There is no way to manage these two cases using admin side settings(means without code touching)? – user3929607 Sep 1 '14 at 6:29
  • If not can you tell me where i need to put javascript code to do this? – user3929607 Sep 1 '14 at 6:30
  • And if i set the cookie life time 300(for store view only), then my cookies are getting updating 2 times in live site but in local it's working fine and expiring the session in 5 minutes – user3929607 Sep 1 '14 at 14:06
  • Ok. And i got the problem like in admin panel i have 2 store views and if i set the value to 300 for any store view, i am getting the cookie names double for like stage.mydomain.com(value-300) & .stage.mydomain.com(value-session). So my setting value(300) is not working. Is there any wrong in my settings? – user3929607 Sep 2 '14 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.