0

Is there anyway to destroy session after closing tabs.

if (!isset($_SESSION['access']) || $_SESSION['access'] != 'yes')
{
    include("FrontPage.php");
    exit();
}

I include this code in some of my application. However it only works when I closes the browser completely. Is this the feature of session or my errors ?

  • Set session expiry time.. –  Feb 09 '14 at 14:03
  • Possible duplicates, 1. http://stackoverflow.com/questions/10958769/destroy-session-when-broswer-tab-closed 2. http://stackoverflow.com/questions/18276226/clearing-session-variables-when-a-tab-is-closed – Vijayakumar Selvaraj Feb 09 '14 at 14:07

2 Answers2

0

The session cookie is per-process not per window. So even if you selected New Window you'd still get the same session id. This behavior makes sense. You wouldn't want a user to re-sign in each time they opened a new window while browsing your site.

I'm not aware off hand of any real way around this.

Answered by Paul Alexander at Why Doesn't Closing A Tab Delete A Session Cookie?

Community
  • 1
  • 1
Magesh Kumaar
  • 1,485
  • 2
  • 10
  • 29
0

I guess you could use something in javascript like:

window.onunload

Maybe to call a script destroying the session with session_destroy()

Psychokiller1888
  • 620
  • 2
  • 10
  • 25