Yii Framework Forum: How To Share Session In Frontend And Backend - Yii Framework Forum

Jump to content

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

How To Share Session In Frontend And Backend Rate Topic: ***** 1 Votes

#1 User is offline   audichya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 15-December 12

Posted 11 February 2013 - 12:20 AM

I have created on project using boilerplate architecture, in this, I have installed an admin module to manage the activities of the site in backend,this admin module is accessible to site admin and registered user to manage their blogs,posts and comments and have installed site module also under frontend to view blogs and posts, I want if user login using frontend then it should be logged in backend also.
When I access
Yii::app()->user->role
in the frontend/site/index/index (1. index is controller and 2.index is action under IndexController) it returns 'admin' as output but when I access
Yii::app()->user->role
under backend/admin/index/index
it returns NULL.

How can I share user session in frontend and backend both?
0

#2 User is offline   Wiseon3 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 14-February 11

Posted 12 February 2013 - 10:46 AM

You need to change your session storage from PHP's default to one that can be shared between domains/subdomains, for example CDbHttpSession.
0

#3 User is offline   audichya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 15-December 12

Posted 21 February 2013 - 07:51 AM

Hi Wiseion3,

As per your suggestion I added following code in both backend/config/main.php and frontend/config/main.php :
'session' => array (
    'class' => 'system.web.CDbHttpSession',
    'connectionID' => 'db',
    'sessionTableName' => 'Session',
),


and created table like this :

CREATE TABLE IF NOT EXISTS `Session` (
`id` char(32) COLLATE utf8_unicode_ci NOT NULL,
`expire` int(11) DEFAULT NULL,
`data` blob,
PRIMARY KEY (`id`)
)

But still no luck, could you please elaborate your solution?

Thanks,


View PostWiseon3, on 12 February 2013 - 10:46 AM, said:

You need to change your session storage from PHP's default to one that can be shared between domains/subdomains, for example CDbHttpSession.

0

#4 User is offline   Venu Gopal Mopidevi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 20-February 12
  • Location:Hyderabad

Posted 22 February 2013 - 12:36 AM

View Postaudichya, on 21 February 2013 - 07:51 AM, said:

Hi Wiseion3,

As per your suggestion I added following code in both backend/config/main.php and frontend/config/main.php :
'session' => array (
    'class' => 'system.web.CDbHttpSession',
    'connectionID' => 'db',
    'sessionTableName' => 'Session',
),


and created table like this :

CREATE TABLE IF NOT EXISTS `Session` (
`id` char(32) COLLATE utf8_unicode_ci NOT NULL,
`expire` int(11) DEFAULT NULL,
`data` blob,
PRIMARY KEY (`id`)
)

But still no luck, could you please elaborate your solution?

Thanks,


@ Dinesh Please try some thing like this :
 'session' => array(
          'sessionName' => 'session',
          'class' => 'CDbHttpSession',
          'autoCreateSessionTable'=> false,
          'connectionID' => 'db',          
          'sessionTableName' => 'Session',
          'timeout' => 300,          
        ),


In user component u need to add below attribute.

'stateKeyPrefix' => 'a prefix for the name of the session variables storing user session data.',


It is working for me. :)
0

#5 User is offline   DrMabuse 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 08-March 12
  • Location:Stuttgart

Posted 06 March 2013 - 05:29 AM

Hello Guys,

anyone cann show me the full example for this on github or bitbucket please. I never used Session before Thx for your Help
... und wenn man hier auf den Knopf drückt fallen die Kühe und die Häuser um das ist dann immer ein ganz großes Hallo .....
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