【问题标题】:Cakephp 3.x how the get the session_idCakephp 3.x 如何获取 session_id
【发布时间】:2015-12-05 10:00:33
【问题描述】:

在 PHP 中,要获取会话 id,我们必须这样使用:session_id();

如何在 Cakephp 3.x 中获取 id?

【问题讨论】:

  • $this->Session->id();应该做的伎俩
  • 谢谢,我相信这是 cakephp 2.x 的方式。

标签: php session-variables session-cookies cakephp-3.0


【解决方案1】:

您可以通过以下方式访问会话 ID,

$this->request->session()->id()

【讨论】:

  • 谢谢,这行得通。但是只有我用session_start();的时候不能正常?
  • @Joost 看看文档:api.cakephp.org/3.0/class-Cake.Network.Session.html#_id 与其他一些方法不同,Session::id() 不会自动启动会话,因此如果尚未启动之前(无论是隐式还是显式),您都必须手动启动它,但不能使用session_start()!,而是Session::start()(不,这不是静态方法)。
  • CakePHP 3.8 更新:$this->request->getSession()->id()
  • 不是 $this->getRequest->getSession()->id() 吗?
  • 不,是$this->getRequest()->getSession()->id()
猜你喜欢
  • 2015-07-01
  • 2012-01-20
  • 1970-01-01
  • 1970-01-01
  • 2018-05-26
  • 1970-01-01
  • 1970-01-01
  • 2017-02-12
  • 2016-05-01
相关资源
最近更新 更多