4

I have started using Yii2 and need to store more information about user in identity. I already know that in Yii2, this should be done using sessions like

Yii::$app->session->set('user.company_id', '121');

This works fine as I am able to get these values later in project using:

Yii::$app->session->get('user.company_id');

. However, these session values are getting wiped up despite user activity on same pages. So after 5-10 minutes, the same user sees some fields based on session value, however, after 1 minute if I refresh the session values go away which should actually happen on session close or user logout.

Any suggestions what I am doing wrong?

Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
Anil Konsal
  • 151
  • 2
  • 11
  • Do you use the default Yii2 User component? – ScaisEdge Apr 19 '15 at 13:03
  • Did you find a solution on this? We are facing the same issue, but there doesn't seem to be a lot of solid information (apart from [this ticket](https://github.com/yiisoft/yii2/issues/5880) ). – marius.7383 Oct 10 '16 at 06:03

1 Answers1

2

First check your app\config\main.php or main-local.php if it contains:

'user' => [
    ...
    'enableAutoLogin' => true,
    ...
],

Second check if you have a proper assignment to the value assigned to the variable:

$authTimeout;
$absoluteAuthTimeout;

See here for more.

arogachev
  • 33,150
  • 7
  • 114
  • 117
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • Doc [says](http://www.yiiframework.com/doc-2.0/yii-web-user.html#$authTimeout-detail) that `$authTimeout` & `$absoluteAuthTimeout` will not work if `$enableAutoLogin` is `true`. – Gianpaolo Scrigna Jul 11 '16 at 07:01
  • @letsjump... i have read...(i don't know if the docs is changed in the last year ) . but for me work as aspected .. – ScaisEdge Jul 11 '16 at 11:12