Problem with Yii session, need help

Hi All,

I have facing problem with session, within the Yii framework, there is no any problem with session. I just set witht his way:




Yii::app()->session['customer_id'] = 'value';



But in my situation now, i already have an portal that is running and it is not using Yii framework. Due to the portal is quite big, i do not plan to change it to Yii, but the new section i did, i have to apply Yii framework, so the Yii framework actually is in the same server with my existing portal. Now the problem is i have a login page in the Yii framework (Normal portal selling product A and Yii framework sell product B, both is link account), i would like to allow user when login from Normal portal or Yii portal, both side also have set the session, so any site is login mean both site also already login. I have to set with Yii session and use normal way call session " $_SESSION[‘variable’] " but it return empty. Can anyone tell me how to assign Yii session that can also use in other area ( not in Yii framework ) but same domain and server.

Thank

What is the problem?

if you don’t store your sessions in database:




$session = Yii::app()->session;

if(!isset($session['test']))

     $session['test'] = 123;

else 

     echo $session['test'];

	 

CVarDumper::dump($_SESSION,10,true);



Hi dckurushin,

did you echo this $session[‘test’] inside the yii framework page or outsite the yii framework page? My problem now is i unable to get the session value when i was echo the session outsite the Yii framework.

my portal now is like this:

normal portal (php without framework) with a new module ( using Yii framework ), so it look like this

www.portal.com is using non-framework, just php and i now start using Yii framework, so i apply in my new module

www.portal.com/yii, so now the problem was when i login from www.portal.com/yii, the session i set i wish to use in www.portal.com but it fail. May i know any method that can solve this problem?

Yii was a good framework but my existing portal was too big, if hard to convert it into Yii framework.

If the domain is the same (and you did not change the default configuration of Yii sessions) you should have shared sessions. The first thing you should do, is to check that both applications use the same session id. Try to insert this in both applications (maybe index.php):




session_start();

echo session_id();



Both should give you the same value. If that’s the case then you should be able to access your legacy session data through Yii::app()->session[…] just fine.

Hi Mike,

THe domain and server was same, is just the different is the main portal was using php to write and without any framework, and the new page i code it in Yii framework, so actually is was in the same place but different framework only. I have try before




session_start();

echo session_id();



but i doesn’t work at all, it just return an empty string. Is there any situation that can cause session overwrite?

dump the session array and look what is inside…

Hi all,

Sorry for late reply, i have try var_dump and it should works in Yii framework only. When i put it in normal portal site (same domain), i was empty. I have try to echo $_SESSION[‘test’] and $session[‘test’] but both fail, session is already start in the normal portal.

I have try to var_dump($_SESSION) in the portal, it return only array(0) { } , mean empty. Any solution for it?

when CVarDumper::dump($_SESSION,10,true); in Yii, it give the correct result.

Hi all,

Anyone can help me on this?

No solution to your problem, because there is no magic.

If you define session, it exists.

Maybe you have very short life for the session in your config or something

Yii session uses simple session array, no magic etc.

try different browser, maybe it buggy

Thank dckurushin, i will try to check what you advice.