douying6206 2019-06-07 02:23
浏览 46

全局无法访问无胖框架SESSION变量

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题