$_SESSION keeps refreshing on every page load

As some of you will know. I am new to Yii and Frameworks really, but I’m having a good time with Yii. I’ve been working on a custom login which I have now got to work (I hope).

However…

I’ve noticed that my session just keeps re-writing itself on ever page load, whether I’m trying to login or not. Obviously this defeats the object of the login and I can’t really check that the login works properly due to this. I’m at a bit of a loss as to what is causing this or where the code for it would be as it doesn’t seem confined to just logging in.

I use XAMPP locally and have no issues with logins on any other custom site.

I have this in my config file:


		'session' => array (

			'autoStart' => true,

			'sessionName' => 'nice new sessions',

			'cookieMode' => 'only',

			'savePath' => '../yii_sessions',

			),



I don’t know if this is even helpful at all, but thought it at least relevant.

I asked on the live chat and Tom mentioned that he vaguely remembered a PHP bug about this, but didn’t know how to correct it. I too have looked on the forum for help, but couldn’t seem to find anything to actually fix the problem.

Does anybody have any ideas?

:)

To update this query. I removed all the session components and tested them all one by one. It turned out that they all caused this problem except for


 'cookieMode' => 'only',

using any other aspect caused the $_SESSION to just start a new.

Remove


'sessionName' => 'nice new sessions',

and everything will be working. Session name defaults to PHPSESSID and that’s cool :).

Also


'autoStart' => true,

already defaults to true so you can remove this line too.

Found this on php.net

For interested people, look at CHttpSession.init() and you’ll see that CHttpSession.open() is called, which starts session and after all properties (like sessionName) are set.

What you think guys?

I think that session_name() needs to be called before session_start() as stated in a manual.

Also check this and be sure php.ini don’t contains this directive.

Thanks ManInTheBox,

I just took out autoStart and SessionName, leaving cookieMode and the path still in there and it still plays up. This is more cosmetics with the name although the save path would be nice to have somewhere outside my root. But as this is my first Yii project (for myself) I’m happy to just roll with it. Just pleased that I got it to properly log in once i removed all the session configs

;D

:lol: noticed this thing , so i read the source code , finally find this:




//  CModule::getComponent      you see CHttpSession is CApplicationCompnent so is is come from this method:


 public function getComponent($id,$createIfNull=true)

        {

                if(isset($this->_components[$id]))

                        return $this->_components[$id];

                else if(isset($this->_componentConfig[$id]) && $createIfNull)

                {

                        $config=$this->_componentConfig[$id];

                        if(!isset($config['enabled']) || $config['enabled'])

                        {

                                Yii::trace("Loading \"$id\" application component",'system.CModule');

                                unset($config['enabled']);

                                $component=Yii::createComponent($config);

                                $component->init();

                                return $this->_components[$id]=$component;

                        }

                }

        }



here you see the properties is set before the init method invoked :D

you can continue to read : Yii::createComponent($config); to see how a array can be used to initialize a instance of some class ;