【问题标题】:Kill Session on browser close Codeigniter 3在浏览器关闭 Codeigniter 3 时终止会话
【发布时间】:2016-09-01 05:54:19
【问题描述】:

我想将 codeigniter 版本 3 中的会话设置为在浏览器关闭时过期。

我已经用谷歌搜索并得到了以下解决方案来解决这个问题。并在应用程序配置中更新以下行

$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = TRUE;

此解决方案完美运行。

但问题是现在浏览器会话仍然在浏览器关闭之前保持有效,这对我的应用程序来说是一种享受。

因此我还想保留 10 分钟的会话过期时间。

因此寻求论坛的帮助以在我的应用程序中实现这两个场景。

提前致谢。

【问题讨论】:

    标签: php session codeigniter-3


    【解决方案1】:

    我认为你使用了这段代码,给你:

    var expireSessionVar = function(e){
      //HERE YOUR CODE WHATEVER YOU WANT
    };
    window.unload = expireSessionVar;
    

    希望对你有帮助。

    【讨论】:

    • 是的,我已经这样做了。但我也想保持过期时间。请仔细阅读问题。
    【解决方案2】:

    应用程序\config\config.php

    /*
    |--------------------------------------------------------------------------
    | Session Variables
    |--------------------------------------------------------------------------
    |
    | 'sess_cookie_name'        = the name you want for the cookie
    | 'sess_expiration'         = the number of SECONDS you want the session to last.
    |   by default sessions last 7200 seconds (two hours).  Set to zero for no expiration.
    | 'sess_expire_on_close'    = Whether to cause the session to expire automatically
    |   when the browser window is closed
    | 'sess_encrypt_cookie'     = Whether to encrypt the cookie
    | 'sess_use_database'       = Whether to save the session data to a database
    | 'sess_table_name'         = The name of the session database table
    | 'sess_match_ip'           = Whether to match the user's IP address when reading the session data
    | 'sess_match_useragent'    = Whether to match the User Agent when reading the session data
    | 'sess_time_to_update'     = how many seconds between CI refreshing Session Information
    |
    */
    $config['sess_cookie_name']     = 'ci_session';
    $config['sess_expiration']      = 600;
    $config['sess_expire_on_close'] = TRUE;
    $config['sess_encrypt_cookie']  = FALSE;
    $config['sess_use_database']    = TRUE;
    $config['sess_table_name']      = 'dbapp_ci_sessions';
    $config['sess_match_ip']        = TRUE;
    $config['sess_match_useragent'] = TRUE;
    $config['sess_time_to_update']  = 300;
    
    /*
    

    只需将$config['sess_expiration']= 7200;设置为$config['sess_expiration'] = 600;,这会将您的会话设置为每10分钟到期一次。此外,如果您将$config['sess_expire_on_close'] = TRUE; 设置为指向,则每次关闭浏览器时会话都会被终止。

    【讨论】:

    • 您能解释一下它将如何解决这两个要求吗?
    • @SamJ 默认会话到期时间为 7200 秒,相当于 2 小时,将 7200 更改为 600 以便您的会话将在 10 分钟后到期。
    • @Fiasal $config['sess_expiration'] = 600 工作正常,但 $config['sess_expire_on_close'] = FALSE;解决方案在浏览器关闭时不起作用。
    • 嗨@FateWell你有什么解决方案吗?
    猜你喜欢
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 2010-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多