在 PHP 中访问非当前用户会话数据
是否可以访问除当前连接客户端($_SESSION)处于活动状态的会话之外的其他用户会话中的数据?
如果是这样,怎么办?
Is it possible to access data in other users sessions than the sessions which is active with the currently connecting client ($_SESSION)?
If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,但这将是一个黑客行为。您必须查看会话存储机制并直接读取它。我相信默认情况下它是文件,存储在
/tmp
中。如果您需要更精确,请考虑定义自己的会话存储机制,然后提供额外的挂钩来完成您想要的任务。
http://www.php.net/manual/ en/function.session-set-save-handler.php
Yes, but it would be a hack. You would have to look at the session storage mechanism and read it directly. I believe it is files by default, stored in
/tmp
.If you need to be more precise about it, consider defining your own session storage mechanism and then providing exta hooks to accomplish what you want.
http://www.php.net/manual/en/function.session-set-save-handler.php
是的,在 session_start() 之前调用 session_id() 并指定您感兴趣的 ID。同一函数还返回当前会话 ID,您可以在其他地方记录或传递该 ID。您可以通过关闭会话、设置新 ID 并重新启动来多次执行此操作。它将透明地提供访问($_SESSION)。请记住将其设置回来,因为它会更新会话 ID cookie。
Yes, call session_id() before session_start() and specify the ID you're interested in. The same function also returns the current session ID, which you can log or pass along elsewhere. You can do this multiple times, by closing the session, setting a new ID and restarting. It'll transparently provide access ($_SESSION). Remember to set it back, because it'll update the session ID cookie.
您可以通过设置会话 ID 来检索会话数据:
http://example.com/index.html php?PHPSESSID=1234
其中 1234
是会话 ID
you can retrieve the session data by setting the session id:
http://example.com/index.php?PHPSESSID=1234
where 1234
is the session id