My website uses the Fat-free-framework, and I am attempting to use the f3 "SESSION" variables with the SQL handler to store a piece of user data after login and access it from a different part of the application. However, even though I can see that the session variables were set properly and show up in the SQL table, attempting to access them in a different function called by API just results in an empty string.
I have a function login() which is called to login the user, and I am attempting to store the user's login token in the session SQL table.
new \DB\SQL\Session($f3->get('db'),'sessions',true,function($session){return true;});
$f3->set('SESSION.token',$user->token);
I can access the variable just fine inside of the login() function:
error_log($f3->get('SESSION.token')); // This works
Now in a different function, login_check(), which is called by our API, I am trying to get the user token from the current session and use it to retrieve their user ID.
error_log('Found session token: ' . $f3->get('SESSION.token'));
$token = $f3->get('SESSION.token');
error_log($token); // This results in an empty string.
I can see in the SQL table's 'data' column that the user token along with some other session variables I set are present. Why am I unable to access them from anywhere else? There are several reroutes inbetween the calls to the two functions, but I was under the impression that SESSION variables would persist across redirects unlike the standard hive variables.
I experienced the same behavior when using the standard PHP session handler instead, by removing the call to "new \DB\SQL\Session()" and just using $f3->set(). Switching to SQL was an attempt to fix it, but I still experience the same problem. Could this be due to the API requests I am making in between functions, or an issue with the server configuration? I have been extremely stumped on this, any help is greatly appreciated.