【问题标题】:Session doesn't expire or user logged out after browser close in a Firefox pinned tab在 Firefox 固定选项卡中关闭浏览器后会话未过期或用户注销
【发布时间】:2015-05-26 17:47:54
【问题描述】:

问题来了

在所有浏览器和 Firefox 未固定标签页上一切正常 ,但在 Firefox 固定标签的情况下: 关闭浏览器并再次返回时,,,仍然登录

我使用这两行来强制会话在浏览器关闭时过期。

ini_set('session.cookie_lifetime', 0);
session_set_cookie_params(0);

【问题讨论】:

    标签: php session firefox cookies tabs


    【解决方案1】:

    在浏览器关闭时使用session_destroy() 函数。
    注销.php

    //This is the page that will destroy all your session, call the code on this page before the browser is closed.
    <?php session_start();
    
    session_destroy();
    
    ?>
    

    我的页面.php

    <script> // use ajax call to execute the code on before unload page mypage.hp
    
    window.onbeforeunload = function(){ //send a small ajax call to logout.php so that the session wil get destroyed 
         $.ajax({
         method:'post',
         url: 'logout.php',
         data: 'nothing'
         })
    }
    
    </script>
    

    【讨论】:

    • 会话在浏览器关闭后已经销毁,但没有 FF 固定选项卡以及如何在浏览器关闭时完成会话,session_destroy
    • 你在浏览器关闭时尝试session_destroy()功能了吗?
    • aha ,, 你的意思是我必须在 .. window.unload 上使用 Ajax 调用这个页面?
    • 是的,就像我在 mypage.php 示例中向您展示的一个示例。
    • 这不起作用,因为此函数在页面刷新时执行操作:(
    猜你喜欢
    • 2017-01-17
    • 1970-01-01
    • 2014-10-12
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    相关资源
    最近更新 更多