It is better to use REMOTE_ADDR
$ip = $_SERVER['REMOTE_ADDR'];