1

My project is using three different services and now I never can get sessions values, I've tried the laravel site tutorial and fallowing link question : Laravel - Session returns null

But none of them worked!

In the first, i used this library:

use Session; 

In a controller class :

$result = SocketHelper::sendRequest($req);

Session::put('uuid', $result->uuid);
Session::save();

Session::put('userId', $result->userID);

return Redirect::route('login_step_two');

In an other method :

$uuid = Session::get('uuid');

$userId = Session::get('userId');

But these are null! does I have to use cookie? I recently upgrade to laravel 5.4

Please help me! It's made me confused!

Thanks.

Fatemeh Asadi
  • 83
  • 1
  • 11
  • Firstly, what version have you upgraded from? Also, where are you trying to access the session e.g. in the routes file, in a controller method, in the `__construct` method in a controller? – Rwd Aug 30 '17 at 06:59
  • it was 5.2 and i first upgraded to 5.3 then 5.4, and now I'm using session in controllers, three of methodes, I mean it's needed to put session in auth method and get in tow other methods. – Fatemeh Asadi Aug 30 '17 at 10:19

4 Answers4

2

Try saving Session explicitly like this, give it a try it worked for me, hope same for you.

Session::put('test_session', 'test message');
Session::save();

And retrieve it like this

echo Session::get('test_session');

And forget it like this:

Session::forget('test_session');
Session::save();
Gaurav Rai
  • 900
  • 10
  • 23
1

I understood the null result was becouse I was posting the value of $request to an other template and it was changed it the way :))) ! so easy to know !

Fatemeh Asadi
  • 83
  • 1
  • 11
0

Have you properly upgraded to laravel 5.4?

Laravel Docs Sessions

Symfony Compatibility

Laravel's session handlers no longer implements Symfony's SessionInterface. Implementing this interface required us to implement extraneous features that were not needed by the framework. Instead, a new Illuminate\Contracts\Session\Session interface has been defined and may be used instead. The following code changes should also be applied:

All calls to the ->set() method should be changed to ->put(). Typically, Laravel applications would never call the set method since it has never been documented within the Laravel documentation. However, it is included here out of caution.

All calls to the ->getToken() method should be changed to ->token().

All calls to the $request->setSession() method should be changed to setLaravelSession().

l.g.karolos
  • 1,131
  • 1
  • 10
  • 25
  • here is part of my codes: Session::put('uuid', $result->uuid); //to set session $uuid = Session::get('uuid');// to get session in an other method of the controller class but i recieve null I didn't understand the first part of ur answer , do i need to implement Illuminate\Contracts\Session\Session interface now? and isn't it implemented on new frameworks? where should i do that? which class/path? – Fatemeh Asadi Aug 30 '17 at 10:24
  • do u have any idea? – Fatemeh Asadi Aug 31 '17 at 05:29
  • IF you were using `SessionInterface` then yes you have to change it and use 'Session' now – l.g.karolos Aug 31 '17 at 06:57
0

Do you still have the rights to write session files in php session directory ? Check the path returned by session_save_path() and check if your php user has the rights to write in it, check also if there is files in the directory and what are their creation date.

EkinOf
  • 451
  • 1
  • 7
  • 18
  • thx for ur answer, i used this method and saw the path was: C:\xampp\tmp while framework/session is given in config/session and a new file is added to this path! – Fatemeh Asadi Aug 30 '17 at 10:15
  • Ok I guessed you were in Linux environment, but if you are on Windows and Session seems to work, it's probably a problem with the framework. Check other answers. – EkinOf Aug 30 '17 at 11:44