Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果使用yii2,则不会在Google Chrome中删除cookie_Php_Yii_Yii2 - Fatal编程技术网

Php 如果使用yii2,则不会在Google Chrome中删除cookie

Php 如果使用yii2,则不会在Google Chrome中删除cookie,php,yii,yii2,Php,Yii,Yii2,我使用框架Yii2。当我作出以下决定时: Yii::$app->user->login($this->getUser(), 60);//cookies for 60 seconds 浏览器Google Chrome在60秒过期后不会删除Cookie 如果我不使用框架Yii2: setcookie("test", time() + (60), "/"); 一切正常 为什么,如果您使用Yii2,那么在浏览器GoogleChrom中删除cookie不起作用?Yii::$ap

我使用框架Yii2。当我作出以下决定时:

Yii::$app->user->login($this->getUser(), 60);//cookies for 60 seconds
浏览器Google Chrome在60秒过期后不会删除Cookie


如果我不使用框架Yii2:

setcookie("test", time() + (60), "/"); 
一切正常



为什么,如果您使用Yii2,那么在浏览器GoogleChrom中删除cookie不起作用?

Yii::$app->user->login($user,$duration)仅设置浏览器关闭时_identity-cookie处于活动状态的时间

要在设置的非活动时间后注销某人,您必须将持续时间设置为
null
,并在用户组件中添加
'authTimeout'=>60

common\models\LoginForm.php

frontend\config\main.php

Yii2附带了大量文档,我建议您看看:

您是否有
enableSession=false
?@Jorgen我有:
用户=>['identityClass'=>'app\models\user','enableAutoLogin'=>true',identityCookie'=>['name'=>'\u identity','httpOnly'=>false,],
@Jorgen我没有
enableSession=false
@Jorgen我应该在哪里设置这个-
enableSession=false
?你不应该:)这会让Yii忽略$duration变量非常非常感谢!但是我看不懂cookies:
$cotest3=Yii::$app->getRequest()->getCookies()->getCookies()->getValue(“\u identity”)
identity-cookie用于保持用户登录浏览器关闭。您需要什么信息?可以在
Yii::$app->user->identity>中访问它
'id'=>'100',username'=>'admin',password'=>'admin',authKey'=>'test100key',accessToken'=>'100 token',
但我无法读取cookie的信息此信息未存储在cookie中。您可以使用
Yii::$app->user->identity
类访问信息。示例getId()和getAuthKey()。密码不是以纯文本形式存储的,也不应该是。为什么在
return Yii::$app->user->login($this->getUser(),null);
中指定持续时间为
null
...
return Yii::$app->user->login($this->getUser(), null);
...
...
'components' => [
    'user' => [
        'identityClass' => 'common\models\User',
        'enableAutoLogin' => true,
        'authTimeout' => 60,
    ],
...