如何禁用会话,cookie和自动登录Yii2? [英] How to disable sessions, cookies and auto login in Yii2?

查看:1931
本文介绍了如何禁用会话,cookie和自动登录Yii2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Yii2中构建无状态restfull API。所以我在我的高级应用程序布局中创建了新的APP(由Yii2创建者优先选择),并配置所有必要的东西和API工作。

现在我想让它无状态 - 我想要禁用会话,我想要在我的API应用程序中的 config / main.php 中完成,以确保它作为全局设置。



我还要禁用cookies和自动登录。



到目前为止,我一直在玩的是Module类

 <?php 
namespace api\modules\v1;

使用\app\models\User;
使用yii\filters\auth\HttpBasicAuth;

类模块扩展\yii\base\Module
{
...
public function init()
{
parent :: init();
\Yii :: $ app-> user-> enableSession = false;
\Yii :: $ app-> user-> enableAutoLogin = false;
}
...
}

在Chrome上使用POSTMAN访问数据我可以看到:




  • 设置了Cookie(PHPSESSID,_csrf,_identity)

  • 我总是收到要求输入用户名和密码的弹出窗口。



感谢您的帮助!

解决方案

最后我发现了什么问题。 Yii2工作正常,但Postman有一些数据存储从过去,当Cookie和会话启用。什么帮助我删除浏览器的历史(包括Cookie),关闭浏览器的所有实例并重新运行。


I am building stateless restfull API in Yii2. So I created new APP in my advanced app layout (as preferred by Yii2 creators) and configure all necessary things and API worked.

Now I want to make it stateless - I want to disable session and I want it to be accomplished in config/main.php inside my API app to ensure it as global setting.

Also I want to disable cookies and auto login.

What I have been playing now so far is inside Module class

<?php
namespace api\modules\v1;

use \app\models\User;
use yii\filters\auth\HttpBasicAuth;

class Module extends \yii\base\Module
{
    ...
    public function init()
    {
        parent::init();        
        \Yii::$app->user->enableSession = false;
        \Yii::$app->user->enableAutoLogin = false;
      }
    ...
}

But when trying to access data using POSTMAN on Chrome I can see that:

  • Cookies are set (PHPSESSID, _csrf, _identity)
  • I always get popup asking for username and password

Thanks for your help in advance!

解决方案

Finally I found out what the problem is. Yii2 worked OK, but Postman had some data stored from the past when cookies and session were enabled. What helped me was deleting browser's history (including cookies), close all instances of browser and rerun.

这篇关于如何禁用会话,cookie和自动登录Yii2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆