Find logged in user by IP?

This may be a strange request, but it came up yesterday when I was checking my statcounter live visitors stream and saw that someone from Belgium was clearly logged in because they were on the s2member user page that you get redirected to after login. I don’t have many members in all the non-English speaking countries in the world combined, so I wondered if someone had shared a login or something else.

When I tried to search users for the IP of this Belgium visitor, of course nothing came up. You can’t search WP users by IP even though there is an initial logged in/registration IP listed for each user when you Edit user.

So I’m wondering, again, am I missing something or is there no way to find out what username an IP is associated with for someone logged in and visiting the s2member restricted page right now.

I tried searching for plugins that might do this but most seem related to accomplishing finding the IP of a known user, the reverse of what I’m trying to do,

s2Member does track the IP Addresses of Users, at least if you have Unique IP Restrictions enabled. That said, I don’t believe there is a “log” and I don’t know how they are tracked in the database. You could check the usermeta table for everything prefaced with s2_ to see if you can identify those values.

That said, if what you are trying to prevent is sharing of login information, then take a look at the IP Access Restrictions. They should do what you need done. WP Dashboard → s2Member (Pro) → Restriction Options → Brute Force IP/Login Restrictions.

I suggest installing a logging plugin like Activity Log. That will log all sorts of things that happen on your site, including logins with IP addresses.

There exists a usermeta “*_s2member_registration_ip”, so maybe can search there? But this is a manual job (my plugin “KC Tools” may help), not a s2M feature.

krumch, thanks for the answer idea. I installed your plugin and set the password but I’m not finding any documentation on how to use the usermeta you gave me with the IP address I have. I know mysql but it’s not clear what to enter. Perhaps you can give me an example string to enter on this page wp-admin/options-general.php?page=kctools
Thanks, Tim

Try this (but replace square brackets with the actual info, which I don’t know):

First put this SQL request in my plugin’s “DB” tab:

select user_id from [your DB prefix here]usermeta where meta_key='[your DB prefix here]s2member_registration_ip' && meta_value='[the IP you search for]'

This should show you the ID of the user, who register with this IP (or nothing, if not find). Then open a new tab/window in your browser and use this URL:

http://[your domain and path to WP here]/wp-admin/user-edit.php?user_id=[the ID you find by plugin]

This will open the profile of that user.

Happy hunting! And be careful, my plugin works directly with your DB, so if you do mistake, you can destroy the site… So backup it before any play.

1 Like