$ip2=$_SERVER["HTTP_X_FORWARDED_FOR"]; $ip4=$_SERVER["REMOTE_ADDR"]; if(empty($ip2)) $ip=$ip4; else if(!empty($ip2))$ip=$ip2; else $ip=$ip4;