function get_client_ip(){ $headers = array('HTTP_X_REAL_FORWARDED_FOR', 'HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR'); foreach ($headers as $h){ $ip = $_SERVER[$h]; // unknown if ( isset($ip) && strcasecmp($ip, 'unknown') ){ break; } } if( $ip ){ list($ip) = explode(', ', $ip, 2); } return $ip; }