简体   繁体   English

在Laravel中获取另一个PHP应用程序的会话数据

[英]Get session data of another PHP application in Laravel

I have two domain in same hosting one is using Custom PHP and another Laravel 5.4 . 我在同一托管中有两个域,一个是使用Custom PHP ,另一个是Laravel 5.4 I have set some value in session variable using custom PHP using $_SESSION . 我已经使用$_SESSION使用自定义PHP在session变量中设置了一些值。 And Now after login its redirect to laravel . 现在,登录后将其重定向到laravel。 Now my question is how can I get this Session variable inside laravel . 现在我的问题是如何在laravel获取此Session变量。

you can use session() helper function. 您可以使用session()辅助函数。 or Session Facade. Session外观。

suppose you want to put something in session you can use 假设您想在会话中放一些东西可以使用

Session::put('key', 'this is something in session');

if you want to access the same 如果您想访问相同的

echo Session::get('key') //outputs this is something in session

Laravel doesn't use native PHP sessions since Laravel 4.1 . Laravel 4.1开始, Laravel不使用本地PHP会话。

We are no longer using Symfony's (and therefore PHP's) session handling facilities, and are using a custom solution that is simpler and easier to maintain 我们不再使用Symfony(以及PHP)的会话处理工具,而使用的定制解决方案更易于维护。

In Laravel you want to use Session:: facade or session() global helper to work with sessions: 在Laravel中,您想使用Session:: facade或session()全局帮助器来处理会话:

// Saving value.
session()->put('key', 'value');

// Gettinng value.
session('key');

So you cannot access session data from another PHP application, 因此,您无法从另一个PHP应用程序访问会话数据,

But you may be able to access the session from another Laravel app if you are using the same storage for session management for both apps ( Redis , Memcached , shared session folder, ...) and you use the same APP_KEY (look in your .env file) and the same cookie identifier (look in your config\\session.php file) in both apps. 但是,如果您对两个应用程序( RedisMemcached ,共享会话文件夹等)使用相同的存储空间进行会话管理,并且使用相同的APP_KEY (请在中查看),则可以从另一个Laravel应用程序访问会话.env两个应用程序中都包含一个.env文件)和相同的Cookie标识符(在config\\session.php文件中查找)。

您可以使用适当的名称空间\\Session来访问Session外观

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP Laravel:如何设置或获取会话数据? - PHP Laravel: How to set or get Session Data? 如何与另一个 PHP 应用程序共享 Laravel 会话? - How do i share Laravel session with another PHP application? 如何在同一服务器上的Web应用程序(Core PHP)和另一个Web应用程序(Laravel)之间共享会话? - How to share Session between Web Application (Core PHP) and another Web Application (Laravel) on Same Server? 如何通过同一域中托管的另一个laravel应用程序访问php应用程序的会话? - How to access session of a php application via another laravel application which hosted in same domain? Laravel 5.2在MongoDB内部具有会话 如何从外部PHP应用程序读取会话数据? - Laravel 5.2 with session inside MongoDB. How to read the session data from an external PHP application? 获取 php session 数据 - Get php session data 如何在一个方法中设置会话并在laravel 5.2中的另一个方法中获取会话数据 - How to set session in one method and get the session data in another method in laravel 5.2 在Laravel之外获取Laravel会话数据(Memcached) - Get Laravel session data (Memcached) outside of Laravel Laravel会话在另一个选项卡中的GET请求上重置 - Laravel session resets on GET request in another tab 如何使用另一个应用程序维护PHP会话状态 - How To Maintain PHP Session State With Another Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM