1 Introduction
Session is a way to preserve certain data across subsequent user accesses. A visitor accessing your web site is assigned a unique id, the so-called session id which stored in the cookie.
Yii allows to use different session storage:
- CHttpSession – for storing session if file
- CDbHttpSession – for storing session in database
- CCacheHttpSession – for storing session in cache
CHttpSession mainly used with simple infrastructure, when you have single server or set of servers which don’t need to share session data between them
CDbHttpSession and CCacheHttpSession are used in more complex infrastructure. When you have set of servers, load balancing between them, and need that user session shared between all servers.
CCacheHttpSession – used in GPN by default cause they more fast than CDbHttpSession. If you use simple infrastructure with one server you can set in config another session storage.
Below is configuration of Yii session component
'session' => array( 'class' => 'system.web.CCacheHttpSession', //The session cookie parameters. 'cookieParams' => array( //If true cookie will only be sent over secure connections. 'secure' => true, //Cookie domain, for example 'www.php.net'. To make cookies visible on all subdomains then //the domain must be prefixed with a dot like '.php.net'. 'domain' => 'example.com' //Lifetime of the session cookie, defined in seconds. 'lifetime' => 0, //Path on the domain where the cookie will work. Use a single slash ('/') for all paths on the domain. 'path' => '/' //If set to true then PHP will attempt to send the httponly flag when setting the session cookie. 'httponly' => false ), ),
class can be one of: CHttpSession, CDbHttpSession, CCacheHttpSession
Also you can set up cookie parameters.