Client IP address using PHP

17-02-2015
You may need to capture your visitor IP address for several purpose. There are several ways to do this in PHP. Here are a simple script you may find below for this purpose.

if (getenv(HTTP_X_FORWARDED_FOR)){        
$ip=getenv(HTTP_X_FORWARDED_FOR);   
}elseif(getenv(HTTP_CLIENT_IP)){

$ip=getenv(HTTP_CLIENT_IP);

}else{

$ip=getenv(REMOTE_ADDR);

}
echo $ip;
?>