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

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

问题描述

我正在开发一个laravel项目,需要工作除了自定义php项目,因为我需要访问纯PHP全局$ _SESSION和$ _COOKIE在laravel应用程序。

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天全站免登陆