Using $ _SESSION in Laravel From a non-laravel Project

In my company, we do login in one application (non-laravel). When the login is done, we save the session information in $ _SESSION variables, for example $ _SESSION ['XPTO'].

The user has access to many tools (all non-laravel), and we use $ _SESSION ['XPTO'] everywhere to get the data we need about the authenticated user.

The problem is that I developed a new tool with Laravel 5.3, and I need to get the data inside the $ _SESSION variables. I think laravel does not use native php sessions!

So how can I get this information?

Thank you in advance

+5
source share
3 answers

Laravel does not use native PHP sessions with Laravel 5.

We no longer use Symfony's session processing capabilities (and therefore PHP), and use a custom solution that is simpler and easier to maintain

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

 // Saving value. session()->put('key', 'value'); // Gettinng value. session('key'); 
+1
source

Laravel provides a more built-in method for getting and setting session data. its easy to work with the session in laravel.A session variable is used to store some information or some data about the user or whatever you want to get on all pages of the application. In the session configuration, laravel is stored in "app/config/session.php" .

I found here a very simple tutorial to understand the use of SESSION in laravel, which you can also find in a convenient for training.

Setting a separate variable in a session: -

Following is the session syntax

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

Example: -

 Session::put('email', $data['email']); //array index Session::put('email', $email); // a single variable Session::put('email', ' sharmarakesh395@gmail.com '); // a string 

Getting value from a session: -

Syntax for retrieving values ​​from a session

Syntax: - Session::get('key');

Example:

 Session::get('email'); 

Checking a variable exists in a session: -

 // Checking email key exist in session. if (Session::has('email')) { echo Session::get('email'); } 

Removing a variable from a session: -

Syntax

: - Session::forget('key');

Example:

 Session::forget('email'); 

Removing all variables from a session: -

 Session::flush(); 
+1
source

to access $_SESSION just place session_start() at the beginning of the index.php file of your laravel project

0
source

Source: https://habr.com/ru/post/1258022/


All Articles