[英]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. 但是,如果您对两个应用程序(
Redis
, Memcached
,共享会话文件夹等)使用相同的存储空间进行会话管理,并且使用相同的APP_KEY
(请在中查看),则可以从另一个Laravel应用程序访问会话.env
两个应用程序中都包含一个.env
文件)和相同的Cookie标识符(在config\\session.php
文件中查找)。
您可以使用适当的名称空间\\Session
来访问Session外观
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.