1

I have a legacy application that handles auth and sets some session variables; I need access to those session variables in a Laravel app. I tried starting a session and accessing one of the variables in a controller - this did not work. I get a Whoops Error - Undefined index: name
Here is what I tried:

public function __construct() 
    {
        session_start();
    }

public function index()        
    {
       //test output php (not Laravel) sessions   
       echo "TEST CONTROLLER ACCESSED!!\n\n";  
       print_r($_SESSION['name']);
    }

I also tried the same method in a closure within the route. Both failed.

Is there a way to access the PHP native session variable within Laravel?

Edit
I do not understand my question being marked as a duplicate. The answer referenced is regarding the error that I get. It does not answer my question. I understand what the error means, I need to know why the session is not available to Laravel.

Please let me know of any additional information you need.
Edit 2
$_SESSION['name'] exists in the legacy app, but is not passed to Laravel. Both apps are on the same server and domain. How can a trace what is happening?

Roger Creasy
  • 1,419
  • 2
  • 19
  • 35
  • Try looking into the session super global with `dd($_SESSION)`. That will give you more insight into the structure of the raw session data. – aknosis Sep 26 '17 at 20:41
  • You're accessing it just fine. Just use `if(isset($_SESSION['name']))` to check that `$_SESSION['name']` exists before you go using it. – ceejayoz Sep 26 '17 at 20:42
  • @ceejayoz please explain how my question is a duplicate. I do not understand. – Roger Creasy Sep 26 '17 at 20:49
  • it just means the `name` index doesn't exist. – Wreigh Sep 27 '17 at 00:51
  • @ceejayoz OK. The variable is not getting passed from the legacy app to Laravel. $_SESSION['name'] exists in the legacy app, then is not passed to Laravel for some reason (same server and domain). How can I trace why this is happening? – Roger Creasy Sep 27 '17 at 00:54
  • 2
    @RogerCreasy, I'm not sure why he marked it as duplicate either. The connected answer has nothing to do with what you are looking for.. Hopefully this helps. You can set session variables with `session(['team_id' => $team_id]);` and you can access them like so: `session($team_id)` – parker_codes Sep 27 '17 at 00:54
  • @GoogleMac I closed it as a dupe because, pre-edit, the problem statement was "I get a Whoops Error - Undefined index: name". The inability to access session data *after* fixing that error message was added after the closing. – ceejayoz Sep 27 '17 at 01:29

1 Answers1

0

I am posting this in hopes that it helps someone else.

It turns out that the legacy app uses a non-standard session.save_path (I am working with a very large code base. So, this fact was not as obvious as it may seem).

The solution was to set the save path to the same location in Laravel. ini_set('session.save_path', '/path/to/sessions/');

This has to be done prior to session_start()

See info on the PHP command here.

Roger Creasy
  • 1,419
  • 2
  • 19
  • 35