Find user ip using php
by Guna[ Edit ] 2012-07-23 14:54:38
This function lets you to get real ip of the user. This function retrives the user's ip as follows:
Returns a user ip if exists, otherwise it returns proxy ip from using "http_forwarded_for". If both are
failed it returns network ip using remote_addr property.
function get_real_ip(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
#ip from share internet
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
#check ip is pass from proxy
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else {
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
echo $ip = get_real_ip();