Process frontend and backend logon in yii

Source: Internet
Author: User

If you need to separate front-end member login from background administrator login, You need to customize two different verification mechanisms for front-end and background login, mainly by defining different sessions. To solve this problem, you must use different cwebuser instances in the front and backend to log on. In this way, the frontend and backend logon points have been removed. However, if you exit, you will find that the frontend and backend are exited together. So I found the logout () method and found that it has a parameter $ destroysession = true. It turns out that, if you only use logout (), all sessions will be logged out, if the parameter "false" is added, the session of the currently logged-on instance will be canceled.

    Yii::app()->user->logout(false);

Main. php

Front-End User (cwebuser) configuration: useridentity

'User' => array ('class' => 'webuser', // This webuser inherits the cwebuser. The Code 'statekeyprefix' => 'Member 'will be provided later ', // This is the prefix of the front-end session 'allowautologin' => true, // here it is set to allow the cookie to save the login information, while the next automatic login ),


Backend user (cwebuser) configuration: adminidentity

'Admin' => array ('class' => 'adminwebuser', // background logon class instance 'statekeyprefix' => 'admin ', // background session prefix "guestname" => "visitor "),

Yii: APP ()-> User // frontend User Information Access Method

Yii: APP ()-> admin // Method for accessing user information in the background

  Yii::app()->admin->login($this->_identity,$duration);


Process frontend and backend logon in yii

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.