For personal Kohana framework Session and Cookie usage tutorials, please leave a message. I. use Session in Kohana: Session: instance ()-& amp; gt; set ('A', 'thisisv
For personal Kohana framework Session and Cookie usage tutorials, please leave a message.
I. Session usage in Kohana:
Session: instance ()-> set ('A', 'This is value of session'); // set the session value echo session: instance () -> get ('A'); // get the session value Session: instance ()-> delete ('A'); // delete the session value of the specified key Session :: instance ()-> destroy (); // destroy all session values
In fact, the Session has different adapters. by default, the above is used as Native without configuration.
- Native: stores session data on your web server by default. For example, if you are running PHP on Apache2, session data is stored in the file specified by the path set in your php. ini file by default.
- Database: stores session data in a Database. (Database module required)
- Cookie: stores session data in a local cookie.
II. Cookie usageSet the salt value in bootstrap. php before using the Cookie. Otherwise, an error message is displayed.
Cookie: $ salt = 'phpddt. com'; // The salt value of the custom Cookie. Otherwise, an exception occurs.
Of course, you can also set other values:
// Set how long the cookie expires. Cookie: $ expiration = 43200; // restrict valid cookie paths. Cookie: $ path = '/'; // restrict the domain name cookie that can access the Cookie: $ domain = 'www .phpddt.com '; // you can transmit cookieCookie only through a secure connection: $ secure = TRUE; // The cookie can be transmitted only over HTTP, but cannot be transmitted using Javascript. Cookie: $ httponly = TRUE;
Cookie usage:
Cookie: set ('phpddt ', 'This is www.phpddt.com'); // set cookieCookie: set ('newtest', 'This is new test', 10 ); // Set the cookie expiration time, in seconds. echo Cookie: get ('phpddt '); // Obtain cookieecho Cookie: get ('newtest '); // The Cookie cannot be obtained after 10 s: delete ('phpddt '); // delete the cookie value of the specified key
Next I will write about the session database adapter configuration