Yii Framework Forum: wildcard subdomain with CDbHttpSession issue - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

wildcard subdomain with CDbHttpSession issue wildcard subdomain with CDbHttpSession issue Rate Topic: -----

#1 User is offline   heamon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 15-March 10
  • Location:Beijing.China

Posted 13 November 2010 - 12:47 PM

I have do a website with Yii, it use wildcard subdomain. To control the session, I use CDbHttpSession
Here is the code in main.php

'session'=>array(
'class' => 'CDbHttpSession',
'connectionID' => 'db',
'sessionTableName' => 'dbsession',
),

When login in with domain 'www.xxx.com', then it will redirect to 'subdomainname.xxx.com'.
But now, the user show it's not login in subdomainname.xxx.com, when change url to www.xxx.com, it show user is login.
Is there anything I do wrong?
Any reply is appreciate!
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 13 November 2010 - 12:53 PM

You have to set $cookieParams, by default the session cookie is only visible to the domain from which it was set.

'session'=>array(
   'class' => 'CDbHttpSession',
   'connectionID' => 'db',
   'sessionTableName' => 'dbsession',
   'cookieParams' => array(
      'domain' => '.example.com', // cookie now visible on example.com and all subdomains
   ),
),


If you make use of CWebUser::$allowAutoLogin, you have to do the same for the user component. Instead of $cookieParams, it's called CWebUser::$identityCookie.
1

#3 User is offline   heamon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 15-March 10
  • Location:Beijing.China

Posted 13 November 2010 - 01:01 PM

View PostY!!, on 13 November 2010 - 12:53 PM, said:

You have to set $cookieParams, by default the session cookie is only visible to the domain from which it was set.

'session'=>array(
   'class' => 'CDbHttpSession',
   'connectionID' => 'db',
   'sessionTableName' => 'dbsession',
   'cookieParams' => array(
      'domain' => '.example.com', // cookie now visible on example.com and all subdomains
   ),
),


If you make use of CWebUser::$allowAutoLogin, you have to do the same for the user component. Instead of $cookieParams, it's called CWebUser::$identityCookie.

It works like a charm, thank you very much! really appreciate!
0

#4 User is offline   swafsarl 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 20-February 10

Posted 14 March 2011 - 10:54 AM

Quote

If you make use of CWebUser::$allowAutoLogin, you have to do the same for the user component. Instead of $cookieParams, it's called CWebUser::$identityCookie.


how to manage this? didnt understand!
plz help
0

#5 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 18 March 2011 - 10:23 AM

View Postswafsarl, on 14 March 2011 - 10:54 AM, said:

how to manage this? didnt understand!
plz help


Like this:

'user'=>array(
   'identityCookie' => array(
      'domain' => '.example.com', // cookie now visible on example.com and all subdomains
   ),
),

0

#6 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 485
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 11 May 2012 - 08:54 AM

Thanks Y!!, I've struggled with this for the past few days. My problem was with Chrome because IE worked fine.
José
0

#7 User is offline   Zeam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 15-September 12

Posted 07 November 2013 - 06:28 PM

I had a little problems with this and resolved it by reading this:

http://www.yiiframew...ple-subdomains/

(From article)
Next, and this is the crucial bit with Yii (the above cookie configuration is generic PHP), the Yii application ID must be set in the config file:

array(
'id' => 'yourdomain',

Explanation:

The Yii application ID is used to generate a unique signed key, used as a prefix to access user state information. The ID should be set manually so that it is identical for each Yii application that needs to share cookies and sessions.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users