Session empty.

Hi,

I am setting the session when a user logs in using:




$session=new CHttpSession;

$session->open();

$session['fname'] = $user->firstName;



After login, if I print_r() the session in the default site controller i can see all the values. But when i redirect to the next page I lose the session.

This problem occurs only on the live environment. On the test server everything is working fine.

I have also attached some images of my php session config on the live and test environments.

Thank you, in advance, for your help.

Regards,

Gavin.

  1. You should use Yii::app()->session instead of creating a new CHttpSession object

  2. If problem still occurs, check the output of print_r($_SESSION);

  3. Check if /var/php_sessions is writeable by your webserver

Hi Mike,

Thank you for your reply. I tried your suggestions but it still wont work.

I think the /var/php_sessions directory is writable because the session is being set on the first page. It’s only when I redirect the page that the session is empty.

Any ideas?..

Thank you in advance for your help.

Regards,

Gavin.

Hmm. Do you maybe logout() a user somewhere? Because then the session will be cleared. Besides that, i would experiment with $_SESSION a little to find out, wether it’s a problem with your PHP installation or your Yii session configuration.

Thank you Mike.

I’ll try that out. Will let you know what happens.

it also occures on me. Who knows how can we solve it?

Hi Elbek,

I’m sorry I had not added my solution to this problem :(

But yes! It’s solved. The problem was with the session_save_path of my host server. They were storing it in the home directory of my account.

I suggest you check out the PHP settings on your server. You can use this script




<?php phpinfo(); ?>



Look for the session_save_path variable and check the path. you can also set this using the session_save_path() function.

Hope this helps :)