In the platform development process, the project is divided into the foreground (frontend) www.xxx.com and Backstage (backend) yun.xxx.com two parts, binding two domain names, we know that there is no binding domain name when the front and back can be synchronized login and exit, but the binding domain name after the failure, The reason is that the scope of the session is different. Two domain names of the session scope are limited to their own domain name, our solution is to change the scope of different two domain names to the top-level domain name xxx.com.
In Common/config/main. Add the following code inside PHP:
Cross-domain session domain name configuration, get the current hostname $host _array = explode ('. ', $_server["Http_host"]); For COM domain names, get the top-level domain if (count ($host _array) = = 3) { define (' domain ', $host _array[1]. '.' . $host _array[2]); }//For com.cn domain name ElseIf (count ($host _array) = = 4) { define (' domain ', $host _array[1]. '.' . $host _array[2]. '.' . $host _array[3]); } else{ //echo "This system does not support local access, please configure the domain name"; exit; define (' Domain_home ', ' www. '). DOMAIN); Define (' Domain_yun ', ' YUN '. DOMAIN); Define (' Domain_api ', ' API. '). DOMAIN); Define (' Domain_email ', ' mail. ') DOMAIN); Define (' domain_img ', ' IMG. '). DOMAIN);
Modify components to change session scope
' User ' = [ ' identityclass ' + ' common\models\user ', ' enableautologin ' and ' = True ' Identitycookie ' + ' = [' name ' = ' _identity ', ' httponly ' = ' + ', ' domain ' = '. '. Domain], ' session ' = [ ' cookieparams ' and ' = ' domain ' = '. DOMAIN, ' lifetime ' = 0], ' timeout ' = 3600, ],
With the above configuration, multiple level two domain names can be used to synchronize logins and exits.
The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support topic.alibabacloud.com.