How to access the globals $_SESSION and $_COOKIE from a laravel app?(如何从 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 laravel 应用程序访问全局变量 $_SESSION 和 $_COOKIE?
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
