0

在 Kohana v3 中获取当前访问者会话 ID 的最佳方法是什么?session_id()似乎不起作用,只为我返回 null ..

目前我正在使用cookie::get('session'),但这在您第一次访问该网站时不起作用,我需要这样做。

我知道你可以$this->session->id()在 Kohana v2 中做到这一点,但这似乎在 KO3 中不存在......

谢谢

4

5 回答 5

4

通常,您使用以下 3 种会话类型中的任何一种:本机、Cookie、数据库。

对于cookie,我相信您没有会话ID。即使在使用 cookie 作为会话类型时调用 Session::instance()->regenerate(),它也只会返回 NULL。

对于本机,您应该能够在通过 Session::instance()->regenerate() 返回会话 ID 生成 ID 时获取 ID。

对于数据库,Session_Database 保护了 $_session_id 存储会话 ID 的位置。您可能想要扩展该类并编写自己的 getter。

希望有帮助。

于 2010-05-07T16:40:01.600 回答
4

Kohana 有会话的包装类。该类称为会话。Kohana 允许使用多种驱动程序(例如 memcached)以多种方式存储会话数据。我正在使用本机方式来存储会话数据,如果您不通过 config/session.php 进行任何配置更改,这是默认设置我查看了本机会话的 kohana 代码,发现这将提供会话 ID

Session::instance()->id();

这个对我有用。希望它也适用于你!

于 2012-10-02T06:16:43.890 回答
2

看看这个提交http://github.com/kohana/core/commit/f67b07a69c4e16027ac52fda7a0747c510eee164

于 2010-09-29T19:12:04.600 回答
0

通过查看 GitHub 上的源代码,我似乎找不到返回 id 的方法。

但是,session_id()用于本机驱动程序,因此也许它应该适用于您的情况。

也许如果你session_regenerate_id()先打电话?

于 2010-05-06T12:18:14.077 回答
0

If you're using the database driver then the cookie will hold the session id.

On the other hand it seems to be no direct way to get the session id. As how @SyaZ suggested, you should extend the session class and write your own getter method.

于 2010-05-12T09:54:47.877 回答