0

I have two domain in same hosting one is using Custom PHP and another Laravel 5.4. I have set some value in session variable using custom PHP using $_SESSION. And Now after login its redirect to laravel . Now my question is how can I get this Session variable inside laravel.

5
  • Do you want to get session in laravel controller or in any view file? Commented Feb 14, 2018 at 6:26
  • inside laravel controller. Commented Feb 14, 2018 at 6:28
  • I think it's not possible, but try like first start the session and then use $_SESSION[] Commented Feb 14, 2018 at 6:30
  • i would recommend using database to store the data and redirect to the site that using laravel with a token eg: http://example.laravel/home?_token=somethingRandom, then you can use the token to retrieve the data from the database. Commented Feb 14, 2018 at 6:44
  • Or if it's small data just send it with the URL ex. https://yourdomain.com?myData Commented Nov 21, 2019 at 11:41

3 Answers 3

2

Laravel doesn't use native PHP sessions since Laravel 4.1.

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

In Laravel you want to use Session:: facade or session() global helper to work with sessions:

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

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

So you cannot access session data from another PHP application,

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.

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

6 Comments

Actually I m saving value from custom php and want to get this data in laravel.
@raj I think this means you cant. You will need to find an alternative solution.
@Raj please see my updated answer. basically you can't do it.
@TobyAllen yes. I've added an explanation too
@linktoahref laravel.com/docs/4.2/releases search for "Improved Session Engine"
|
1

you can use session() helper function. or Session Facade.

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

1 Comment

Actually I m saving value from custom php using $_SESSION.and want to get this data in laravel using Session Facade.
-1

You can access the Session facade by using the proper namespace \Session

1 Comment

Are you trying to use it on the front-end? This is how I used the Session facade in a project in the past: @if(\Session::has('feedback')) do x, y, z. has() returns a bool value but you can use get() to access the actual value. edit: Nevermind just saw your new comment about using it on the back-end

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.