Yii2 for Single Sign-on

Source: Internet
Author: User
Tags yii
This time to everyone to bring YII2 to achieve single sign-on, Yii2 realize single sign-on note what, the following is the actual case, together to see.

This article introduces the method of realizing single sign-on in Yii2, and share it with you, as follows:

Modify/common/config/main.php

First, add the following code to the config header

<?php//Session cross-domain $host = explode ('. ', $_server["Http_host"]), if (count ($host) > 2) {  define (' DOMAIN ', $host [1 ] . '.' . $host [2]);} else {  define (' DOMAIN ', $host [0]. '.' . $host [1]);}

Second, add the config in the configuration

<?php ' user ' = [  ' identityclass ' + ' common\models\user ',  ' enableautologin ' and ' = True  ' Identitycookie ' + ' = [' name ' = ' _identity ', ' httponly ' = ' + ', ' domain ' = '. '. Domain], ' session ' = [  ' cookieparams ' and ' = ' domain ' = '. DOMAIN, ' lifetime ' = 0],  ' timeout ' = 3600,],

Third, use of controller

<?php//set Yii:: $app->session[' var ']= ' value ';//Use echo YII:: $app->session[' var '];//remove unset (Yii:: $app- Session[' var ');

Iv. Testing

4.1 www.aaa.com Landing

4.2 www.bbb.com session still works.

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

How PHP generates random numbers

How to use the recursive function of PHP

Related Article

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.