0

If i have my website's tab open on google chrome , along with other tabs are open, session is not destroying if i close my website's tab. To destroy the session i need to close the whole browser, including all tabs. Is ther anyway i can log users out when they close just the website's tab only and not the whole browser? I'm using codeIgniter. and config setting is as below

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 0;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;
user1906399
  • 753
  • 1
  • 13
  • 27
  • if logout is critical for your application, you should put a logout button. – Sharky Sep 19 '14 at 06:59
  • i do have a logout button, but i want even if users don't press logout button and close the site i want them to be logged out – user1906399 Sep 19 '14 at 07:13
  • There's no inherent difference between clicking on a link and closing a tab, opening a new one and typing the URL of the page by hand. There's no inherent "loss of connectivity" or any such thing in both cases. Ending a session when a tab is closed is an entirely arbitrary decision; and the browser doesn't share your opinion in this decision. In other words: it's mostly not possible [reliably]. – deceze Sep 19 '14 at 07:28

1 Answers1

0

PHP will kill a session automatically after 24 min of inactivity. (Correct me if this is not true but I think so) If this is not what you want you could also change the expiration time to be very short and check it via ajax every minute or so.

Are you saving the session data to a database? Why don't you write a php script that deletes expired sessions automatically. You could start it with a cronjob.

Marcus Rommel
  • 1,266
  • 1
  • 12
  • 17
  • You can configure when sessions become invalid. 24 minutes is not hardcoded or anything. – deceze Sep 19 '14 at 07:51
  • Yeah i know that you can configure it. I meant the default session timeout which (as i believe) is set to 1440 seconds (24 minutes) – Marcus Rommel Sep 19 '14 at 07:53