codice:
$ip = getenv('REMOTE_ADDR');

// oppure
$ip = $_SERVER['REMOTE_ADDR'];