Kohana 3.2 在每个请求上重新生成会话 ID
我希望这个问题还没有得到解答,我已经浏览了一段时间,但还没有真正看到答案。
我正在使用带有数据库驱动程序的 Kohana 3.2 会话。问题是每次加载或刷新页面时,都会创建一个新的会话 ID。
我已经在引导程序中设置了 Session::$default = 'database'。我的会话配置如下所示:
return array(
'database' => array(
/**
* Database settings for session storage.
*
* string group configuation group name
* string table session table name
* integer gc number of requests before gc is invoked
* columns array custom column names
*/
'name' => 'trucero_session',
'lifetime' => 1200,
'group' => 'default',
'table' => 'sessions',
'gc' => 500,
'columns' => array(
/**
* session_id: session identifier
* last_active: timestamp of the last activity
* contents: serialized session data
*/
'session_id' => 'session_id',
'last_active' => 'last_active',
'contents' => 'contents'
),
),
);
提前谢谢您。
i hope this hasn't already been answered, I've looked through for awhile and haven't really seen an answer.
I am using Kohana 3.2 sessions with database driver. The problem is that every time the page is loaded or refreshed, it is creating a new session id.
I've set the Session::$default = 'database' in my bootstrap. My session config looks like this:
return array(
'database' => array(
/**
* Database settings for session storage.
*
* string group configuation group name
* string table session table name
* integer gc number of requests before gc is invoked
* columns array custom column names
*/
'name' => 'trucero_session',
'lifetime' => 1200,
'group' => 'default',
'table' => 'sessions',
'gc' => 500,
'columns' => array(
/**
* session_id: session identifier
* last_active: timestamp of the last activity
* contents: serialized session data
*/
'session_id' => 'session_id',
'last_active' => 'last_active',
'contents' => 'contents'
),
),
);
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 Laurent 并没有真正理解你的问题,因为在页面刷新之间应该只创建和使用一个会话 id - 这就是会话的全部意义所在,这样你每次访问一个会话时都可以重复使用同一个会话页。
当您使用新浏览器打开页面,或关闭现有浏览器然后打开新浏览器,或销毁当前会话(例如从页面注销)然后创建新浏览器( ..通过登录)。
但我确实在 Kohana 3.2 中发现了类似的问题,其中我的脚本在每个页面读取时生成多个会话 ID,并且会话没有被“读”回,因为在每个页面刷新/访问时都会创建一个新的 session_id。我能够将这个问题追溯到 Google Chrome 浏览器(就我而言),经过深入研究后,我发现了这篇文章:
http://forum.kohanaframework.org/discussion/10303/session-problem-with-ie-and-chrome/p1
基本上说你必须将 Cookie::domain 设置为FALSE 或特定域,以便 Kohana 数据库会话在 Chrome 和 IE 中正常工作。
I don't think Laurent really understood your question, because there should be only one single session id created and used between page refreshes - that's the whole point of having sessions is so you can re-use the same session every time when you access a page.
A new session ID is created when you open the page either with a new browser, or close the existing browser and then open a new one, or destroy the current session (like by logging out from your page) and then create a new one (..by logging in).
But I did find a similar problem in Kohana 3.2 where my scripts were generating multiple session IDs per each page read and the sessions weren't being "read" back because a new session_id was created at each page refresh/access. I was able to track this issue down to Google Chrome browser (in my case) and after digging around I found this post:
http://forum.kohanaframework.org/discussion/10303/session-problem-with-ie-and-chrome/p1
Which basically says that you have to set Cookie::domain to either FALSE or to a specific domain for the Kohana database session to work properly in Chrome and in IE.
您不能依赖会话 ID,因为它确实会根据每个请求重新生成。如果您需要某种 ID,则必须使用自定义 ID。
You cannot rely on the session ID because it's indeed regenerated on every request. If you need some sort of ID, you'll have to use a custom one.