在线用户的IP。
我想知道如何让当前用户在线及其IP地址。
我知道如何获取客户端 IP 地址,并且知道如何为当前用户使用 cookie 和会话。
我需要的是获取当前用户的IP的逻辑,如果用户离开该网站,它将停止跟踪用户并停止获取用户的IP。
这可能吗?
I was wondering how to get the current users online and their IP address.
I know how to get a clients IP adress and I know how to use cookies and sessions for current users.
What i need is the logic to get the IP of the current user, and if the user leaves the site, it will stop tracking the users and stop getting the users IP.
Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下
print_r($_SERVER)
- 其中有大量有关当前用户的信息。如果用户离开网站,您无法立即检测到 - 但您可以跟踪您最后一次在数据库中看到用户的时间,如果您在(比如)20 分钟内没有看到用户,则无效他们的饼干。
编辑:您可以做的一件事是定期执行 AJAX 操作,每隔 30 秒左右显示“此用户仍然在这里”。然而,这可能会给您的网络服务器带来不必要的压力 - 我之前概述的选项可能更好。
Have a look at
print_r($_SERVER)
- there's loads of info in there about the current user.If the user leaves the site, you can't detect that immediately - but you can keep a track of the last time you saw a user in your database, and if you don't see a user for (say) 20 minutes, invalidate their cookie.
Edit: one thing you could do is have a periodic AJAX operation that says 'this user is still here' every 30 seconds or so. However this arguably puts more stress on your web server than is necessary - the earlier option I outline is probably better.
你可以使用这个获取用户的ip
You can get ip of user using this