沃梦达 / 编程问答 / php问题 / 正文

尽管会话超时设置为至少 1 天,但 Yii 用户仍会在

Yii users being logged out after 15-30 minutes despite session timeouts being set to at least 1 day(尽管会话超时设置为至少 1 天,但 Yii 用户仍会在 15-30 分钟后注销)

本文介绍了尽管会话超时设置为至少 1 天,但 Yii 用户仍会在 15-30 分钟后注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面包含了 Yii 配置文件的相关部分:

I've included the relevent parts of our Yii config file below:

return array(
...
    'components'=>array(
        'session' => array(
            'timeout' => 86400,
        ),
        'user'=>array(
            'allowAutoLogin' => true,
            'autoRenewCookie' => true,
            'authTimeout' => 31557600,
        ),
    ...
    ),
...
);

我也进入了 php.ini 并设置了 session.gc_maxlifetime = 86400 但这仍然没有解决问题.

I have also been into php.ini and set session.gc_maxlifetime = 86400 but this still hasn't fixed the problem.

目前,我完全不知道还有什么可能导致它超时并在大约 15-30 分钟不活动后将用户注销.理想情况下,用户应该保持登录状态至少一天不活动(并且除了关闭浏览器窗口,浏览器首选项允许).

Currently, Im absolutely at a loss as to what else could be causing it to timeout and log the user out after roughly 15-30 minutes of inactivity. Ideally users should remain logged in for at least a day of inactivity (and beyond closing the browser window, browser preferences allowing).

我已经搜索了 google、Yii 和堆栈溢出,但找不到任何我忽略的东西……但显然我忽略了一些东西.如果有人可以帮助我,我将不胜感激.

I've trawled google, Yii and stack overflow and just can't find anything that I'm overlooking... but clearly I am overlooking something. If anyone can help me out I'd be very grateful.

我们用来登录用户的典型代码示例被请求,包含在下面:

A sample of typical code that we are using to log in the users was requested and is included below:

$identity = new UserIdentity('facebook', $id, $user->name, $user->email);
$loggedIn = Yii::app()->user->login($identity);
$this->subscriptionChecker->updateCurrentUserSubscribed();

这是很典型的任何时候 Yii::app()->user->login() 被调用

This is pretty typical of any time that Yii::app()->user->login() is called

在 Chrome 中,以下是我为该网站准备的 cookie 及其到期时间(在清除所有 cookie 并登录后):

From Chrome, here are the cookies I have for the site and their expiries (after clearing all cookies and just logging in):

PHPSESSID expires When the browsing session ends

// I'm informed these are set by google analytics  
__utma created Friday, 12 October 2012 14:05:31 expires Sunday, 12 October 2014 14:05:31

__utmb created Friday 12 October 2012 14:05:31 expires Friday 12 October 2012 14:35:31,

__utmc created Friday, 12 October 2012 14:05:31 expires When the browsing session ends

__utmz created Friday 12 October 2012 14:05:31 expires Saturday 13 April 2013 02:05:31  
// end google analytics

推荐答案

http://www.yiiframework.com/doc/api/1.1/CWebUser#login-detail

感谢 Arfeen 的帮助,他为我指明了正确的方向,除非您设置了 Yii::app()->user->login() 的第二个参数,否则结果是Yii 不会使用持久性 cookie,因为第二个参数默认为 0.这个默认的 0 值会覆盖您可能设置的任何其他超时值.

Thanks to help from Arfeen who pointed me in the right direction, unless you set the second parameter of Yii::app()->user->login() it turns out that Yii will not use a persistent cookie, as the second parameter defaults to 0. This default 0-value overrides anything else you might have set to do with timeouts.

这篇关于尽管会话超时设置为至少 1 天,但 Yii 用户仍会在 15-30 分钟后注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:尽管会话超时设置为至少 1 天,但 Yii 用户仍会在

基础教程推荐