开发者

Save session in database using codeigniter

开发者 https://www.devze.com 2023-04-13 04:04 出处:网络
I have an application made ​​by CodeIgniter. I have made so that it can be installed. When you come to the site I check if database.php available. If it does not exist so I create database.php and

I have an application made ​​by CodeIgniter.

I have made so that it can be installed. When you come to the site I check if database.php available. If it does not exist so I create database.php and my database and tables.

It works fine, but now I have a problem.

I want to save the sessions in the database. (http://codeigniter.com/user_guide/libraries/sessions.html)

To do that I had to change my config.php.

$ config ['sess_cookie_name'] = 'ci_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'] = 'Session';
$ config ['sess_match_ip'] = FALSE;
$ config ['sess_match_useragent'] = TRUE;
$ config ['sess_time_to_update'] = 300;

The problem I have is that since I do not have a database.php from the start, I get an error message when I want to install the application. Error message I get is that database.php missing.

How can I solve this? I have tried using this: $ this-> config-> set_item ('sess_use_database', TRUE);

It has not worked. So any advice is welcome.


You must connect your database (Mysql or MSSQL ...), please modified application/config/databases.php and follow user guide

http://codeigniter.com/user_guide/database/configuration.html

Before using session via database, please add session encryption key to your application/config/config.php, open the file and set:$config['encryption_key'] = "YOUR KEY";

Please referrer the following URL to read "Session Data to a Database" section:

http://codeigniter.com/user_guide/libraries/sessions.html


If you don't mind storing your session variables in the cookie

just set $config ['sess_use_database'] = TRUE; to FALSE.

Since it appears you are not using a database, there is no downside.

There could be one if you decide to implement a DB and then base your queries in the user data. Which would lead to huge security holes in your application.

0

精彩评论

暂无评论...
验证码 换一张
取 消