Recuperar o endere├žo IP do usu├írio

M├ętodo pr├ítico para recuperar o endere├žo IP de um usu├írio. Mesmo quando est├úo se escondendo atr├ís de um servidor proxy.

/**
* Get a user's IP address. Even if they're behind a proxy.

*

* @return string

*/

function get_ip_address() {
$server_vars
= array(
'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED',
'REMOTE_ADDR',
);
foreach ( $server_vars as $key ) {
if ( array_key_exists($key, $_SERVER) !== true ) continue;
foreach ( explode(',', $_SERVER[$key]) as $ip ) {
if ( filter_var($ip, FILTER_VALIDATE_IP) !== false ) {
return $ip;
}
}
}
}

Fonte: http://www.kavoir.com/2010/03/php-how-to-detect-get-the-real-client-ip-address-of-website-visitors.html