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

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

问题描述

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

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.

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

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.

我还想禁用 cookie 和自动登录.

Also I want to disable cookies and auto login.

到目前为止我一直在玩的是在模块类中

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

<?php
namespace apimodulesv1;

use appmodelsUser;
use yiifiltersauthHttpBasicAuth;

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

但是当尝试在 Chrome 上使用 POSTMAN 访问数据时,我可以看到:

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

  • 设置 Cookie(PHPSESSID、_csrf、_identity)
  • 我总是弹出要求输入用户名和密码的窗口

提前感谢您的帮助!

推荐答案

我终于找到了问题所在.Yii2 工作正常,但是 Postman 在启用 cookie 和 session 时存储了过去的一些数据.帮助我的是删除浏览器的历史记录(包括 cookie),关闭浏览器的所有实例并重新运行.

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.

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

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