Yii SSO implementation with single sign-on with domain name

Source: Internet
Author: User

SSO (single sign-on) is the name of a number of sub-projects that share one login point. The principle is simply that server session sharing, client cross-domain cookies.

The implementation is very simple, protected/config/main.php the session configuration can be modified

The code is as follows:

1 $host=Explode(‘.‘,$_server["Http_host"]);2 if(Count($host) > 2) {3     Define(' DOMAIN ',$host[1]. ‘.‘ .$host[2]);4}Else {5     Define(' DOMAIN ',$host[0]. ‘.‘ .$host[1]);6 }7 8 9' Components ' =Array(Ten' User ' =Array( One' Allowautologin ' =true, A' Autorenewcookie ' =true, - //' class ' = ' WebUser ', -' Statekeyprefix ' = ' xxx ', the), -' Session ' =Array( -' Savepath ' = ' C:\session_temp ',//dirname (__file__). Directory_separator. ‘..‘ . Directory_separator. ‘..‘ . Directory_separator. ' Session_temp ',//' C:\session_temp ',// -' Cookieparams ' =Array(' domain ' = '. '). DOMAIN, ' lifetime ' = 0), +),
*****

The above code is implementation code, YII configuration is simple,

Problem

One. Open ' class ' = ' WebUser ', error

Include (webuser.php): Failed to open stream:no such file or directory

This is because the WebUser class is not defined, and a new webuser.php is created under the Protected\components directory, as follows:

1<?PHP2 3 //This file must is stored in:4 //protected/components/webuser.php5 6 classWebUserextendsCwebuser {7 8 //Store model to not repeat query.9  Private $UserLogin;Ten  One //Return First name. A //Access it by Yii::app ()->user->first_name - functionGetfirst_name () { - $user=$this->loaduserlogin (Yii::app ()->user->user_id); the return $user-first_name; - }   -  - //This was a function that checks the field ' role ' + //In the User model to being equal to 1, that's means it ' s admin - //Access it by Yii::app ()->user->isadmin () + functionISAdmin () { A $user=$this->loaduser (Yii::app ()->user->user_id); at return intval($user->user_role_id) = = 1; - } -  - //Load user model. - protected functionLoaduserlogin ($id=NULL) - { in     if($this->userlogin===NULL) -     { to         if($id!==NULL) +             $this->userlogin=userlogin::model ()-&GT;FINDBYPK ($id); -     } the     return $this-Userlogin; * } $}?>

Two. Even though it is configured, the subdomain still shows no sign-in.

This is because the session save location is not in the same place, the Savepath changed to the same place can be

Before modification:

1 ' savepath ' =dirname(__file__

After modification:

1    ' Savepath ' = ' C:\session_temp ',

Yii SSO implementation with single sign-on with domain name

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.