CI Framework 3.0 How to set up the session and how to use the storage database

Source: Internet
Author: User
Tags memcached

The session setting is a little different than before.

Let's take a look at what the settings in version 2.0 look like:

$config [ ‘sess_cookie_name‘ ]=  ‘test_session‘ ; $config [ ‘sess_expiration‘ ]= 7200; $config [ ‘sess_expire_on_close‘ ]= FALSE; $config [ ‘sess_encrypt_cookie‘ ]= FALSE; $config [ ‘sess_use_database‘ ]= TRUE; $config [ ‘sess_table_name‘ ]=  ‘test_sessions‘ ; $config [ ‘sess_match_ip‘ ]= FALSE; $config [ ‘sess_match_useragent‘ ]= TRUE; $config [ ‘sess_time_to_update‘ ]= 3000;And 3.0 is the case: $config [ ‘sess_driver‘ ] =  ‘database‘ ;   $config [ ‘sess_cookie_name‘ ] =  ‘test_session‘ ; $config [ ‘sess_expiration‘ ] = 3600; $config [ ‘sess_save_path‘ ] =  ‘test_sessions‘ ; $config [ ‘sess_match_ip‘ ] = FALSE; $config [ ‘sess_time_to_update‘ ] = 300; $config [ ‘sess_regenerate_destroy‘ ] = FALSE;

First is the first change, CI3.0 supports more ways to store sessions, including files, database, Redis, memcached, and custom.

So you can change the way you want to store it in Sess_driver.

Then the fourth line of changes, line fourth when using the file storage should specify the file path (using the default null), and the use of database storage needs to change the name of the data table, using Redis need to change to a TCP address, such as

tcp://localhost:6379

Use the same memcached to change to an address, such as:

localhost:11211

How does the database work?

First configure in application\config\config.php, then go to database Creation table (MYSQL):

Note: The 3.0 version of the Session data table and 2.0 version of a large difference, it is recommended to delete 2.0 of the data table to replace the new data table "

CREATE TABLE IF  NOT EXISTS `ci_sessions` (          `id`  varchar (40)  NOT NULL ,          `ip_address`  varchar (45)  NOT NULL ,          ` timestamp int (10) unsigned  DEFAULT NOT NULL ,          `data` blob  NOT NULL ,          PRIMARY KEY (id),          KEY `ci_sessions_timestamp` (` timestamp `) );If you want to open sess_match_ip, you also need to execute the following statement ALTER TABLE ci_sessions  ADD CONSTRAINT ci_sessions_id_ip  UNIQUE (id, ip_address);This completes the configuration, and you can use the 2.0 version of the method to make the call.

CI Framework 3.0 How to set up the session and how to use the storage database

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.