PHP - Session destroy after closing browser

前端 未结 9 1461
陌清茗
陌清茗 2020-11-27 07:43

Though this question has multiple duplicates i could not find proper solution for me. Need Some help.

I have used ini_set(\'session.cookie_lifetime\', 0);

9条回答
  •  甜味超标
    2020-11-27 08:27

    Use a keep alive.

    On login:

    session_start();
    $_SESSION['last_action'] = time();
    

    An ajax call every few (eg 20) seconds:

    windows.setInterval(keepAliveCall, 20000);
    

    Server side keepalive.php:

    session_start();
    $_SESSION['last_action'] = time();
    

    On every other action:

    session_start();
    if ($_SESSION['last_action'] < time() - 30 /* be a little tolerant here */) {
      // destroy the session and quit
    }
    

提交回复
热议问题