php CodeIgniter 3 和会话
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28385783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CodeIgniter 3 and sessions
提问by maxime1992
I updated to CodeIgniter 3 recently, following this guide: CI3: upgrade 3.0 from 2.2.1.
我最近按照本指南更新到 CodeIgniter 3: CI3: upgrade 3.0 from 2.2.1。
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...
这里有什么问题吗?几个小时后我的会话被破坏了......
回答by Mr. ED
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.
在您的保存路径中,您需要设置一个位置文件夹。使用'files'
的会话驱动程序优先。如下所示,我设置了一个缓存来将会话存储在设置文件夹的 BASE PATH 中。确保您有自动加载的会话并$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);
回答by David D.
In application/config/config.php set this value:
在 application/config/config.php 设置这个值:
$config['sess_save_path'] = sys_get_temp_dir();
回答by Sergio Gutierrez
I have used 2 different values and somehow they worked, it depends on the version of Centos:
我使用了 2 个不同的值,它们以某种方式起作用,这取决于 Centos 的版本:
For Centos 6.X I 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.X I 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.
如果您在不编辑此值的情况下将应用程序从一个服务器版本移动到另一个服务器版本,它将不起作用。
回答by JGods
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();
}