How to disable sessions, cookies and auto login in Yii2?

末鹿安然 提交于 2019-12-11 04:46:02

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/28738482/how-to-disable-sessions-cookies-and-auto-login-in-yii2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!