简体   繁体   English

CodeIgniter 3和会话

[英]CodeIgniter 3 and sessions

I updated to CodeIgniter 3 recently, following this guide: CI3: upgrade 3.0 from 2.2.1 . 我最近更新了CodeIgniter 3,遵循本指南: CI3:从2.2.1升级3.0

I set up this configuration in application/config/config.php file: 我在application / config / config.php文件中设置了这个配置:

$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... 我的会话在几个小时后就被销毁了......

In your save path you need to set up a location folder. 在保存路径中,您需要设置位置文件夹。 Use 'files' as session driver preferred. 使用'files'作为会话驱动程序首选。 As like below I have set up a cache to store sessions in BASE PATH which is setting folder. 如下所示,我已经设置了一个缓存来存储BASE PATH中设置文件夹的会话。 Make sure you have auto loaded sessions and $config['encryption_key'] = '' add key. 确保你有自动加载的会话和$config['encryption_key'] = ''添加密钥。

You can set up a database sessions but this works just as well. 您可以设置数据库会话,但这也可以。 Make sure folder permissions 0700 确保文件夹权限0700

http://www.codeigniter.com/userguide3/search.html?q=session&check_keywords=yes&area=default 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);

在application / config / config.php中设置此值:

$config['sess_save_path'] = sys_get_temp_dir();

I use this code it work. 我使用这个代码工作。

    if (version_compare(PHP_VERSION, '5.4.0', '<')) {
        if(session_id() == '') session_start();
    } else  {
       if (session_status() == PHP_SESSION_NONE) session_start();
    }

I have used 2 different values and somehow they worked, it depends on the version of Centos: 我使用了2个不同的值,不知怎的,它们有效,这取决于Centos的版本:

For Centos 6.XI used: 对于Centos 6.XI使用:

In application/config/config.php set this value: 在application / config / config.php中设置此值:

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

For Centos 7.XI used: 对于Centos 7.XI使用:

$config['sess_save_path'] = sys_get_temp_dir(); $ config ['sess_save_path'] = sys_get_temp_dir();

it will not work if you move your app from one server version to another without editing this value. 如果将应用程序从一个服务器版本移动到另一个服务器版本而不编辑此值,它将无法工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM