如何从 laravel 应用程序访问全局变量 $_SESSION 和 $_COOKIE?

2022-01-16 00:00:00 session cookies frameworks php laravel

我正在开发一个需要在自定义 php 项目之外工作的 laravel 项目,因为我需要访问 laravel 应用程序中的纯 php 全局变量 $_SESSION 和 $_COOKIE.

I am working on a laravel project that needs to work besides a custom php project, because that I need to get access to the pure php globals $_SESSION and $_COOKIE in the laravel app.

到目前为止,我得到的只是 null 或空.有人知道怎么做吗?

Until now I'm geting just null or empty. Somebody know how to do that?

推荐答案

Laravel 有自己的 $_SESSION$_COOKIE 的实现,所以恐怕你不能通过这些超全局变量访问它们.

Laravel has its own implementations of $_SESSION and $_COOKIE, so I'm afraid you cannot access them via those superglobals.

为了克服这个问题,您可以在 Laravel 应用程序中执行以下操作,将数据从一个传输到另一个:

To try to overcome that, what you can do, in your Laravel app, is to transfer data from one to the other by doing something like:

foreach(Session::all() $key => $value)
{
    $_SESSION[$key] = $value;
}

相关文章