我想知道Yii2框架的会话超时
当浏览器关闭时会自动取消设置会话数据吗?
如果浏览器关闭,可以设置吗?
答案 0 :(得分:0)
会话变量仅在浏览器打开时有效。当您关闭浏览器时,它将被销毁。如果要保留信息,则必须使用cookie。
来自Yii2文档:
您可以使用以下内容在当前请求中获取Cookie 代码:
// get the cookie collection (yii\web\CookieCollection) from the "request" component
$cookies = Yii::$app->request->cookies;
// get the "language" cookie value. If the cookie does not exist, return "en" as the default value.
$language = $cookies->getValue('language', 'en');
// an alternative way of getting the "language" cookie value
if (($cookie = $cookies->get('language')) !== null) {
$language = $cookie->value;
}
// you may also use $cookies like an array
if (isset($cookies['language'])) {
$language = $cookies['language']->value;
}
// check if there is a "language" cookie
if ($cookies->has('language')) ...
if (isset($cookies['language'])) ...
http://www.yiiframework.com/doc-2.0/guide-runtime-sessions-cookies.html#cookies