0

The problem I am facing is my session remains intact if I close the browser without logging out, if I set to restore pages (option "Continue where I left off" in Chrome). I have seen some mainly concern Firefox (link 1, link 2, link 3, but I am facing same in Chrome as well.

So basically here where I stand:

Problem: If user chose the option to restore previously open pages in browser, Session remain intact even if I close browser.

Reason: By design

My PHP Settings:

session.cookie_lifetime = 0
session.cache_expire = 180
session.use_only_cookies = ON

Solution I tried: I tried below by ini_set as per this recommendation

session.cache_expire = 0
session.use_only_cookies = OFF

Solution: Yet to find one.

Community
  • 1
  • 1
abdfahim
  • 2,523
  • 10
  • 35
  • 71
  • Do you want that on specific check user remains on browser other wise on closing browser clear the old entries ? – Mahmood Rehman Dec 26 '13 at 04:40
  • sorry, I was disconnected from net for sometime ... anyway, I need to clear any and all sessions once the browser is closed ... irrespective of user and browser ... – abdfahim Dec 26 '13 at 07:05

1 Answers1

0

You dont have to. The garbage collector will clean up your sessions.

The php ini setting session.gc_maxlifetime determins how long a session can remain active. the session is destroyed when the user closes the browser**.

try this code

ini_set('session.cookie_lifetime', 0);
ini_set('session.use_only_cookies', 0);
ini_set('session.cache_limiter', 0);
Mahmood Rehman
  • 4,303
  • 7
  • 39
  • 76
  • What I need, if anybody closes browser, the session will expire. But if anybody refresh the page, it will not be destroyed. Things happen exactly this way if I don't choose the option "Continue where I left off" in chrome settings. But if I chose that, it just holds the sessions (may be till 24 hrs). Now your code calls that function in every onload, doesn't it mean it will destroy the session if I refresh the page (CTRL+R)? – abdfahim Dec 26 '13 at 07:37
  • Not clear what do you want ? short and in simple words – Mahmood Rehman Dec 26 '13 at 07:40
  • *Session will get destroyed if I close the whole browser .. ** Session will NOT destroy if I refresh page or close ONLY the current Tab. – abdfahim Dec 26 '13 at 07:43
  • it still holds session after I close browser ... I guess it is Chrome/Mozilla's default behavior ... – abdfahim Dec 26 '13 at 07:56
  • 1
    if you made some settings in chrome or firfox then it will work as you set.Not depends upon code – Mahmood Rehman Dec 26 '13 at 07:57
  • hmm, I guess .. I was trying to find something that override browser settings ... – abdfahim Dec 26 '13 at 08:00