如何从 laravel 应用程序访问全局变量 $_SESSION 和 $_COOKIE? [英] How to access the globals $_SESSION and $_COOKIE from a laravel app?

查看:31
本文介绍了如何从 laravel 应用程序访问全局变量 $_SESSION 和 $_COOKIE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要在自定义 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;
}

这篇关于如何从 laravel 应用程序访问全局变量 $_SESSION 和 $_COOKIE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆