Not sure why I haven't posted this before. (or maybe I did and I'm just drawing a blank). Get the IP of the user:
if ($_SERVER['HTTP_X_FORWARD_FOR']) {
$ip = $_SERVER['HTTP_X_FORWARD_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
I've also seen it done this way too but for some reason I was under the impression the method above was more reliable:
$ip = $REMOTE_ADDR;
If you want to resolve the domain name of the IP (as seen here):