cakephp 会话 ID 为空

发布于 2024-11-02 01:43:09 字数 600 浏览 1 评论 0原文

当我执行以下操作时,会话 ID 为空: pr($this->Session); 我收到:

SessionComponent Object
(
    [__active] => 1
    [__bare] => 0
    [valid] => 1
    [error] => 
    [_userAgent] => 5343528de22b8a6d25e7fd391692c911
    [path] => /profiles
    [lastError] => 
    [security] => medium
    [time] => 800-452-3639
    [sessionTime] => 800-452-3639
    [cookieLifeTime] => 720000
    [watchKeys] => Array
        (
        )

    [id] => 
    [host] => xyz.org
    [timeout] => 
    [enabled] => 1
)

如何启用会话 ID 或创建会话 ID?

The session id is empty when I do: pr($this->Session);
I receive :

SessionComponent Object
(
    [__active] => 1
    [__bare] => 0
    [valid] => 1
    [error] => 
    [_userAgent] => 5343528de22b8a6d25e7fd391692c911
    [path] => /profiles
    [lastError] => 
    [security] => medium
    [time] => 800-452-3639
    [sessionTime] => 800-452-3639
    [cookieLifeTime] => 720000
    [watchKeys] => Array
        (
        )

    [id] => 
    [host] => xyz.org
    [timeout] => 
    [enabled] => 1
)

How do I either enable the session id or make the session id?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

GRAY°灰色天空 2024-11-09 01:43:09

如果您确实需要会话 ID,则需要启动会话。在之前的过滤器中尝试一下:

$this->Session->start();
$this->Session->id(session_id());

然后当您 pr($this->Session->id()); 时,您将看到新的会话 ID。

If you really want a session id, you need to start the session. Try this in your before filter:

$this->Session->start();
$this->Session->id(session_id());

Then when you pr($this->Session->id()); you will see the new session id.

掩饰不了的爱 2024-11-09 01:43:09

它由 Cake 被动处理 - 您不需要设置它。只需根据需要调用 read()、write() 即可。

$this->Session->write('key', $value);

$value = $this->Session->read('key');

It's passively taken care of by Cake - you don't need to set it. Just make calls to read(), write() as needed.

$this->Session->write('key', $value);

$value = $this->Session->read('key');
若水般的淡然安静女子 2024-11-09 01:43:09

只需使用

echo $this->Session->id(); //打印类似7gl7bo9gv38rj0sjtqo52dkeu5

//在控制器中 。不需要 start() 或其他东西。 Cakephp(在 2.7 中测试)会自动为您提供它。

Just use

echo $this->Session->id(); //prints like 7gl7bo9gv38rj0sjtqo52dkeu5

in controller. There is no need to start() or something else. Cakephp (tested in 2.7) automatically makes it available for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文