某个页面一次只有两个人?
我不太确定如何在保证相当多的安全性的情况下实现这一点。我希望能够知道是否有人或两个人基于 mysql 行。这两个人完全匿名。我确实设置了一个 xmpp 服务器,但我不确定它如何集成到 mysql 中,而且我已经有一个单独的登录系统了。服务器端是用 PHP 完成的
编辑:我只想允许两个人在某个页面上,仅此而已。但是,如果他们离开页面,我需要确定他们是否已经离开。
I'm not really sure how I would implement this along with a fair amount of security. I want to be able to know if someone or two people are on based on a mysql row. These two people are totally anonymous. I do have an xmpp server set up but I'm not sure how that would integrate into the mysql and I already have a separate login system for it. Server side is done with PHP
Edit: I want to ONLY allow two people on a certain page and that is it. But, if they leave the page I need to determine if they have left.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是,如果有人关闭浏览器,您将无法收到他们已离开页面的通知。
您可以做的是在页面上发出 AJAX 请求,以便每 10-15 秒向服务器发送一个包含会话 ID 的请求。将时间戳和会话 ID 记录在表中,然后您可以查询数据库以查看过去 15 秒内发出了哪些请求
The issue is that if somebody closes their browser you have no way of being notified that they have left the page.
What you could do is have an AJAX request on the page, so that every 10-15 seconds it sends a request to the server containing a session id. Log the timestamp and the session id in a table, and you can then query the database to see what requests have been made in the last 15 seconds
您可以尝试使用 OnBeforeUnload 事件的解决方案,以通知您用户已离开页面,请参阅 检测用户何时离开网页的最佳方式。
You could try a solution using the OnBeforeUnload event, to notify you that a user has left the page, see best way to detect when user leaves a web page.
当您说“页面”时,您正在谈论浏览器端验证,因为浏览器应该能够告诉您用户仍在该页面上。如果你想这样做,那么你需要 AJAX,就像 waitforatrain 的评论一样。但也存在一些漏洞:
1)如果浏览器禁用了javascript怎么办?
2)如果用户在加载页面后处于非活动状态怎么办?页面应该保持“活跃”吗?
When you say "page" you are talking about browser-side-validation, because browser should be able to tell you that the user is still on that page. If you are trying to do this then you need AJAX like waitforatrain's comment. But there are some loopholes:
1) what if browser has javascript disabled?
2) what if user is inactive after loading the page? Should the page be kept "alive" ?