session problem

I created a feedback form (actionFeedback) in SiteController which does not require any login.

I save some values in $_SESSION.

After, I access the same page to check the values set in $_SESSION.

I cannot see any $_SESSION global variable at all.

Does yii clear the session at some point automatically?

Hi, you must use CHttpSession, you can reade about it in class reference.

Example from class reference:

$session=new CHttpSession;




foreach($session as $name=>$value)


Even though the example in the class reference says so, you don’t need to create a new CHttpSession object. Just access your session like this:


It will auto-open the session by default, which probably was your problem (not opened session).

Thank you for your reply both!

I can write to the session using:


But my problem is I cannot read from the session the value of ‘name1’ in the subsequent requests.

It does not find the matching session from the previous http request.

The webpages are accessed without login (non-authenticated user).

Does Yii only keeps persistent session for authenticated user?

Yii uses the standard PHP session system, no magic. Must be a problem with your setup. Did you try with a script outside of Yii but in the same directory?

Thank you Mike.

I moved the action to set the session variable and the action to read (the same) the session on the same Controller (before they were in two different controllers). Now it is working. (I can read out what I set.) I don’t know if this makes sense.


I am having strange problems too^^

anyways I’m wandering why moving the session access to the same controller actually changes anything??

shouldn’t it work alson in another controler?? as long as you stay in the framework?


if you are using path url style check session cookie params… the controller/action url can be treated as path for session cookie. It is just a guess but it could explain why it is working with same controller (same url path, only last part interpreted as filename change) and not with different controllers (different url paths)