1

I use SimpleUsers Class and created a database-based login system. Here is SimpleUsers on Github

Here is my question: How to terminate PHP session on windows close? When the windows closed the session for logged in user is open yet. How can I close it? I tried to use

session_set_cookie_params(0);

But it was not helpful. Please help me.

  • This might help http://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php – Vojko Dec 25 '15 at 12:08

1 Answers1

1

I assume that by "windows" you mean tab of the browser/window of web browser.

Simple answear is: you can't unless user requests. You can try some kind of javascript code with "onclose" method that will send request to your site to close session. Cons of this method is when someone have 2 tabs and at last one is closed, he will be logged out

You should only destroy sessions only when someone hits Logout button.

Edit to comments

If you want to secure (bind) session to IP you may want to store in $_SESSION IP of user who started session and terminate session if IP changes

if($_SESSION['user_ip'] !== $_SERVER['REMOTE_ADDR']){
    // do the code to terminate session.
}
Grzegorz
  • 3,538
  • 4
  • 29
  • 47