当用户从前端登录时,Yii2 登录可以访问后端 [英] Yii2 login give access to backend when user login is from frontend

查看:34
本文介绍了当用户从前端登录时,Yii2 登录可以访问后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 yii2 高级模板中.

In yii2 advance template.

如果我执行以下操作,即使前端和后端有两个不同的数据库配置,我也无需登录即可访问后端

If i am doing following i get the access of back-end without login, even if there are two different databases configuration for front-end and back-end

  1. 从前端登录页面登录.
  2. 成功登录前端后.
  3. 当我打开后端链接时,它显示已登录.
  4. 后端无需登录.
  5. 签证 - 如果我做相反的事情,则相反.

如何限制?

推荐答案

您必须在 config/main.php 文件中为前端和后端设置不同的 cookie.例如:

You have to set different cookies for frontend and backend in config/main.php file. For Eg.:

在后端:

'components' => [
        'session' => [
            'name' => 'BACKENDID',   //Set name
            'savePath' => __DIR__ . '/../tmp', //create tmp folder and set path
        ],
    ],

在前端:

'components' => [
        'session' => [
            'name' => 'FRONTENDID',
            'savePath' => __DIR__ . '/../tmp',
        ],
    ],

就是这样.

这篇关于当用户从前端登录时,Yii2 登录可以访问后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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