Laravel 5.3 Session not closing

时间:2016-10-20 13:04:03

标签: laravel session laravel-5 laravel-5.3

I closed the browser without logging off. I saw the closure of the session when I open the browser again.The session when the browser closes must also shut down. can you help me?

3 个答案:

答案 0 :(得分:0)

Session is used to prevent to loose data when you close the browser so I don't think there is a "correct" way to do that.

You can flush your session data with

$request->session()->flush();

Otherwise you can try to delete the Laravel Cookie when you .unload() the window.

答案 1 :(得分:0)

答案 2 :(得分:0)

Laravel sessions is a server side, but browser close is a client side event. You can send additional request on browser close or just delete cookies. It will looks like:

window.onbeforeunload = function () {
    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}