从 CLI 到浏览器共享会话 ID
我有一个从浏览器到在 CLI 上作为 websocket 服务器运行的 php 脚本的 websocket 连接。
我让客户端发送其位于服务器上的 session_id 我知道哪个用户拥有哪个会话。
它可以完美地读取单个用户的 $_SESSION 。
我这样做(在服务器端[我的 CLI 代码]):
$sess_ini = ini_get('session.save_path');
$save = file_get_contents("$sess_ini/sess_$sessionID");
session_id($sessionID);
$sessions = explode("|",$save);
$_SESSION['values'] = (isset($sessions[1])?
unserialize(trim(urldecode($sessions[1]))):array());
然后,当我在 CLI 服务器端操作 $_SESSION['values'] 时,它不会反映在客户端会话上,并且会话不会被操作。我该如何将被操纵的会话发送回客户端?
谢谢!
I have a websocket connection from the browser to a php script running as a websocket server on CLI.
I have the client send its session_id that was on the server i know which user has which session.
It works perfectly to read the $_SESSION of the individual users.
i do (on the server side [my CLI code]):
$sess_ini = ini_get('session.save_path');
$save = file_get_contents("$sess_ini/sess_$sessionID");
session_id($sessionID);
$sessions = explode("|",$save);
$_SESSION['values'] = (isset($sessions[1])?
unserialize(trim(urldecode($sessions[1]))):array());
Then when i manipulate $_SESSION['values'] on the CLI server side it does not get reflected on the client session and the session is not manipulated. how do i make it so the manipulated session is sent back to the client?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 sessionId 写入数据库中的用户表
与 CLI 和 Web 相比,您必须使用以下命令:
You could write sessionId to users table in DB
And than in CLI and Web your must use this:
我的代码中有一个错误。
会话正在保存,我只是忽略在更改之前输出它,所以看起来它从未改变。
There was an error in my code.
The session was being saved, i just neglected to output it before it was changed so it looked like it never changed.