CodeIgniter 3和会话 [英] CodeIgniter 3 and sessions
问题描述
我最近更新到CodeIgniter 3,遵循以下指南:
CI3:从3.0版升级3.0 。
I updated to CodeIgniter 3 recently, following this guide: CI3: upgrade 3.0 from 2.2.1.
我在application / config / config.php文件中设置了此配置:
I set up this configuration in application/config/config.php file:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session_my_site';
$config['sess_expiration'] = 604800; // 1 week
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
这里有什么问题吗?我的会话在几个小时后销毁...
Is there something wrong here? My session is destroyed after a few hours...
推荐答案
在您的保存路径中,您需要设置一个位置文件夹。使用'files'
作为首选会话驱动程序。如下面我已经设置了一个缓存来存储会话在BASE PATH是设置文件夹。确保您已自动加载会话,并且 $ config ['encryption_key'] =''
添加键。
In your save path you need to set up a location folder. Use 'files'
as session driver preferred. As like below I have set up a cache to store sessions in BASE PATH which is setting folder. Make sure you have auto loaded sessions and $config['encryption_key'] = ''
add key.
可以设置一个数据库会话,但这也工作得很好。确保文件夹权限为0700
You can set up a database sessions but this works just as well. Make sure folder permissions 0700
http://www.codeigniter.com/userguide3/search.html?q=session&check_keywords=yes&area=default
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 1440;
$config['sess_save_path'] = BASEPATH . 'yourfoldername/cache/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
一旦这样做,你应该能够做。
Once that is done then you should be able to do something like.
$this->load->library('session');
$data_session_set = array('logged' => 1, 'username' => $this->input->post('username'), 'user_id' => $this->user_auth->get_id());
$this->session->set_userdata($data_session_set);
这篇关于CodeIgniter 3和会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!