A pretty good way to get IP, especially, your site has different servers, i.e. load balancing.
function get_ip(){if (isset($_GET['ip'])) {$ip = stripslashes($_GET['ip']);} elseif (isset($_SERVER) and !empty($_SERVER)) {if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];} else if (isset($_SERVER['HTTP_CLIENT_IP'])) {$ip = $_SERVER['HTTP_CLIENT_IP'];} else {$ip = $_SERVER['REMOTE_ADDR'];}} else {if (getenv('HTTP_X_FORWARDED_FOR')) {$ip = getenv('HTTP_X_FORWARDED_FOR');} else if (getenv('HTTP_CLIENT_IP')) {$ip = getenv('HTTP_CLIENT_IP');} else {$ip = getenv('REMOTE_ADDR');}}return $ip;}