2

I have two app in one server, the first is Laravel based and the second is a pure PHP app.

Now I want to save some variables in the session in laravel and use it in my pure PHP app.

I tried various ways to store session variables but any of them won't worked.

Session::put('key', 'value');

$request->session()->put('key', 'value');

$_SESSION['key'] = 'value';

None of the above storing method allowed me to fetch the session in my pure PHP app.
I print_r($_SESSION) this in pure PHP app and return null.

3
  • 1
    It's not a good idea to use the same session for two apps. Use shared DB or Redis or API to share the data between apps. Commented Jan 24, 2018 at 14:05
  • Why don't you implement your logic into laravel app? Commented Jan 24, 2018 at 14:21
  • @shukshin.ivan because its an old app and I want to add new features in laravel Commented Jan 24, 2018 at 14:24

2 Answers 2

1

Laravel does not use the Session to save its sessions, it uses, file, cookie, redis or other drives, which is why you can not access directly in $ _SESSION.

https://laravel.com/docs/5.4/session#configuration

Sign up to request clarification or add additional context in comments.

6 Comments

so how can I use $_SESSION in laravel?
You must to use global helper to work with sessions: // Saving value. session()->put('key', 'value'); // Gettinng value. session('key');
If you are writing an external session to Laravel and want to use it inside Laravel, then you need to use the $ _SESSION itself. If you are using the Laravel helpers, this data can only be accessed within it.
You don't know any way to use this data in other app?
You can use other drives such as Redis or database to share session data.
|
-1

I think you forgot using session_start() before use $_SESSION. Please try it.

2 Comments

No, I didn't forget. I placed session_start() in first line of code
I think you need to define your key with $_SESSION variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.