Ci framework session class, how to use ci session class

Source: Internet
Author: User
How to use the ci session class? Favorites for use. I have always liked the ci framework, but I have rarely used it recently. In my spare time study, how do I use session classes that stick to ci for everyone? Favorites for use. I have always liked the ci framework, but I have rarely used it recently. Study in your spare time and stick it to everyone to initialize the Session.

Sessions starts to run after each page is loaded. Therefore, the session class must be initialized first. You can initialize it in the controller or automatically load it in the system ). Most session classes run in the background. Therefore, when a session is initialized, its session data is automatically read, created, and updated.

To initialize the session class in your controller constructor, you can use the $ this-> load-> library function:

$ This-> load-> library ('session ');

Once loaded, the session can be used as follows: $ this-> session

How does Sessions work?

After the page is loaded, the session class checks whether the user's cookie contains valid session data. If the session data does not exist (or has expired), a new session is created and saved in the cookie. If the session data exists, its information will be updated and the cookie will be updated at the same time. The session_id value will be re-generated for each update.

You need to know that the session class runs automatically once it is initialized. You can ignore the subsequent things. As you will see below, you can use the session to work normally, or even add your own session data. in all these processes, read, write, and update operations are automatically completed.

What is Session data?

A session is composed of an array containing the following information:

  • Unique user Session ID (this is a very robust random string calculated by the average amount of information. it is encrypted using MD5 and is regenerated every five minutes by default.
  • User IP address
  • User browser information (first 120 characters)
  • The latest active timestamp.

The above data will be serialized and stored in the cookie in the following array format:

[Array]
(
'Session _ id' => random hash,
'IP _ address' => 'string-user ip address ',
'User _ agent' => 'string-user agent data ',
'Last _ activity' => timestamp
)

If you enable the encryption settings, the serialized array is encrypted first and then saved to the cookie. This will make the data not easy to see and modify, thus improving security. You can find

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.