简体   繁体   English

在线用户的IP。

[英]IP for online users.

I was wondering how to get the current users online and their IP address. 我想知道如何使当前用户及其IP地址联机。

I know how to get a clients IP adress and I know how to use cookies and sessions for current users. 我知道如何获得客户的IP地址,也知道如何为当前用户使用cookie和会话。

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. 我需要的是获取当前用户IP的逻辑,如果用户离开该站点,它将停止跟踪用户并停止获取用户IP。

Is that possible? 那可能吗?

Have a look at print_r($_SERVER) - there's loads of info in there about the current user. 看一下print_r($_SERVER) -那里有关于当前用户的大量信息。

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. 如果用户离开该网站,则无法立即检测到该信息-但您可以跟踪上次在数据库中看到该用户的时间,并且如果(例如)在20分钟内没有看到该用户,则使该用户无效他们的饼干。

Edit: one thing you could do is have a periodic AJAX operation that says 'this user is still here' every 30 seconds or so. 编辑:您可以做的一件事是定期进行AJAX操作,每隔30秒左右说一次“此用户仍在这里”。 However this arguably puts more stress on your web server than is necessary - the earlier option I outline is probably better. 但是,可以说这给您的Web服务器带来了不必要的压力-我概述的较早的选项可能更好。

您可以使用此获取用户的ip

$ipAdrressOfUser=$_SERVER["REMOTE_ADDR"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM