610   CodeIgniter

1,CI2的session采用的是cookie方式,而且有bug,一直被诟病;
2,CI3终于解决这个问题啦,它采用多种session保存方式,包括php原生的file,数据库,redis等

下面来看看CI3的session配置,在application/config/config.php文件

// 支持更多方式保存session,包括 files, database, redis, memcached
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
// 这个根据sess_driver而改变,下面会说到
$config['sess_save_path'] = "ci_sessions";
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

各种保存方式:
1.在files驱动器下,sess_save_path指的是session文件保存的路径。。

$config['sess_save_path'] =  'your_sess_save_path';

2. 在database情形下,sess_save_path指代的是保存session的数据表名,如:

$config['sess_driver'] = 'database';
$config['sess_save_path'] = 'ci_sessions';

3.在redis情形下,需要安装redis的php扩展。sess_save_path指代的是主机和端口地址,如:

$config['sess_driver'] = 'redis';
$config['sess_save_path'] = 'tcp://localhost:6379';

4.在memcached情形下,也需要安装Memcached的php扩展,sess_save_path指代的也是主机和端口地址,如:

$config['sess_driver'] = 'memcached';
$config['sess_save_path'] = 'localhost:11211';

更多资料




Leave a Reply

Your email address will not be published. Required fields are marked *