1 function getIP(){
 2     $ip = "";
 3     if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) 
 4         $ip = getenv("HTTP_CLIENT_IP"); 
 5     else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) 
 6         $ip = getenv("HTTP_X_FORWARDED_FOR"); 
 7     else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) 
 8         $ip = getenv("REMOTE_ADDR"); 
 9     else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) 
10         $ip = $_SERVER['REMOTE_ADDR']; 
11     else 
12         $ip = "0.0.0.0";
13     return $ip;
14 }