【问题标题】:Is it possible to get session ID from cookie?是否可以从 cookie 中获取会话 ID?
【发布时间】:2019-09-29 01:43:03
【问题描述】:

我从几天前开始学习 Laravel,对 Laravel 中的身份验证如何工作有点困惑。会话存储在哪里?

【问题讨论】:

  • 我在谷歌的第一次搜索中发现了这个PHP Default Session Storage (File System): In PHP, by default session data is stored in files on the server. Each file is named after a cookie that is stored on the client computer. This session cookie (PHPSESSID) presumably survives on the client side until all windows of the browser are closed.
  • 关于 laravel 身份验证的讨论太广泛了,您能分享一下当前代码的确切问题吗?
  • 是的,我想知道会话 ID 在哪里?在 cookie 中

标签: laravel session authentication


【解决方案1】:

从 cookie 中获取会话 ID?

我不完全确定你从 cookie 中获取它的意思,但你可以试试下面的代码。

进口

use Illuminate\Support\Facades\Crypt;

代码

Crypt::decrypt(
  \Request::cookie(
     config('session.cookie')
  )
)

获取会话 ID

我无法对此进行测试,但我相信它应该可以工作,'session()' 是一个全局变量,因此不需要任何导入。

代码

$id = session('id');

希望这回答了你的问题,祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 2018-10-30
    • 2012-08-09
    • 2015-02-14
    • 1970-01-01
    相关资源
    最近更新 更多