Session Lifetime

How do i correctly set the session lifetime or cookie parameters in general ??





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

		print_r($session->cookieParams);

		$param = array();

		$param["lifetime"] = 3600;

		$session->setCookieParams($param);

		print_r($session->cookieParams);



the second print_r works, the first, after reloading the page, not

The CHttpSession documentation says that the parameters you need have to set before the session is started.

In the How to implement session timeout? thread you can find examples how you can set session timeout.

For cookieParams it should be exactly the same.

is the session already started after


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

is called ?

Yes, unless autostart is set to false.

But there’s no need to make things complicated, you can simply set this in config:




'components' => array(


   ...


   'session' => array(

      'cookieParams' => array(

         'lifetime' => 300,

      ),

   ),


),



if i try to set this property i get following error:




CWebApplication.session is read only.


455         }

456     }

457 

458     /**

459      * Configures the module with the specified configuration.

460      * @param array $config the configuration array

461      */

462     public function configure($config)

463     {

464         if(is_array($config))

465         {

466             foreach($config as $key=>$value)

467                 $this->$key=$value;

468         }

469     }

470 

471     /**

472      * Loads static application components.

473      */

474     protected function preloadComponents()

475     {

476         foreach($this->preload as $id)

477             $this->getComponent($id);

478     }

479 



Check your configuration array again. You probably haven’t put the ‘session’ section inside the ‘components’ array.

that was the case, thx