Codeigniter使用相同的用户数据创建新的会话行

时间:2013-07-04 08:47:09

标签: codeigniter session cookies session-cookies

我正在使用HMVC模块化扩展在Codeigniter中开发大型Web应用程序,并在使用数据库时存在会话问题(存储会话)。

我的会话因为我无法理解的原因而丢失。

一个主要的例子是使用Codeigniter购物车。我可以成功地将商品添加到购物车中,然后点击会话中剩余商品的网站。但是,当点击/暂停导航网站约3分钟(没有计时到秒)时,购物车会丢失所有产品并且会话为空。在查看数据库时,旧会话仍然存储在包含内容的数据库中,但创建了新的会话行(如下所示)。

DB Sessions

我正在运行最新版本的Codeigniter,没有对原始Session.php类的扩展。

以下是我的会话配置变量:

/*
|--------------------------------------------------------------------------
| Session Variables
|--------------------------------------------------------------------------
|
| 'sess_cookie_name'        = the name you want for the cookie
| 'sess_expiration'         = the number of SECONDS you want the session to last.
|   by default sessions last 7200 seconds (two hours).  Set to zero for no expiration.
| 'sess_expire_on_close'    = Whether to cause the session to expire automatically
|   when the browser window is closed
| 'sess_encrypt_cookie'     = Whether to encrypt the cookie
| 'sess_use_database'       = Whether to save the session data to a database
| 'sess_table_name'         = The name of the session database table
| 'sess_match_ip'           = Whether to match the user's IP address when reading the session data
| 'sess_match_useragent'    = Whether to match the User Agent when reading the session data
| 'sess_time_to_update'     = how many seconds between CI refreshing Session Information
|
*/
$config['sess_cookie_name']     = 'myhmvc_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']      = 'users_sessions';
$config['sess_match_ip']        = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;

/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix' = Set a prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path'   =  Typically will be a forward slash
| 'cookie_secure' =  Cookies will only be set if a secure HTTPS connection exists.
|
*/
$config['cookie_prefix']    = "my";
$config['cookie_domain']    = "myhmvc.co.uk";
$config['cookie_path']  = "/";
$config['cookie_secure']    = FALSE;

非常感谢任何帮助,愿意在此阶段尝试任何事情。

1 个答案:

答案 0 :(得分:0)

我还没有理解Codeigniter的会话问题,但是从阅读其他帖子来看,默认会话存在很多问题。

我已经安装了这里看到的会话驱动程序: http://getsparks.org/packages/session-driver/versions/HEAD/show

现在已经解决了这个问题。

我希望这可以帮助那些遇到类似问题的人。