Kohana framework Session and Cookie usage tutorial

Source: Internet
Author: User
Tags kohana
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.