Ability to capture IP address of user?

Does CMS Membership plugin have the ability to capture and record users IP address?

Thanks
nmsinc

Re: [nmsinc] Ability to capture IP address of user?

By Dave - September 27, 2011

Hi nmsinc,

No, it doesn't, but you could do that pretty easily with a little custom code.

The users IP address is always stored in $_SERVER['REMOTE_ADDR']

So if you have a recent CMSB version you could create a field in the accounts table called 'last_ip' use the mysql_update() function like this:

// Save users last IP
$usersIpHasChanged = ($CURRENT_USER && $CURRENT_USER['last_ip'] != $_SERVER['REMOTE_ADDR']);
if ($usersIpHasChanged) {
mysql_update('accounts', $CURRENT_USER['num'], null, array('last_ip' => $_SERVER['REMOTE_ADDR']));
}


That code is untested, but that should point you in the right direction. Let me know if that works for you or if you have any other questions.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Ability to capture IP address of user?

Hey Dave,

This would be a good thing to tie into core functionality... especially for user sign-ups to the membership database etc, but also purely on records being edited...

Just another one for the list ;)
Cheers,

Tim (toledoh.com.au)