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
0
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