' flags/small', BIG => ' flags/big'); var $flag_ext = 'png'; function getctrybycode($code) { $countryArray = array(); $input = ROOTPATH . "resources/ip2country/countries.dat"; $fd = fopen($input,"r") or die("Error: cannot open $input!"); while ($buffer = fgets($fd,4096)) { $buffer = preg_replace("/\n/","",$buffer); //chomp() $pieces = explode(",",$buffer); $countryCode = $pieces[0]; $countryName = $pieces[1]; $countryArray[$countryCode] = $countryName; } fclose($fd); return $countryArray[$code]; } /*************************************************************************************/ /*this function returns a country name corresponding to a hostname*/ function getctrybyhost($hostname) { return($this->getctrybycode($this->getctrycodebyhost($hostname))); } /*************************************************************************************/ /*this function returns a country code name corresponding to a hostname*/ function getctrycodebyhost($hostname) { return(substr(strrchr($hostname,'.'),1)); } /*************************************************************************************/ /*this function mask an IP address different from current client using '#' it returns an unaltered IP if same than client*/ function MaskOtherIP($IP) { if($IP==getenv("REMOTE_ADDR")) return($IP); $IP=strtr($IP,"0123456789","##########"); return($IP); } /**************************************************************************** * Jabba: return client's IP address ***************************************************************************/ function getClientIP() { $IP = getenv('REMOTE_ADDR'); return $IP; } /**************************************************************************** * Jabba: return client's hostname * failure: return empty string ("") ***************************************************************************/ function getClientHostname($ip=false) { $error = 0; if(!$ip) $IP = $this->getClientIP(); else $IP = $ip; $hostname = gethostbyaddr($IP); if(!strcmp($hostname,$IP)) $error = 1; // if failure, gethostbyaddr() returns the IP if (!$error) //if no error { return $hostname; } //else return false; } /**************************************************************************** * Jabba: return client's country * failure: return empty string ("") ***************************************************************************/ function getClientCountry($ip=false) { $error = 0; $hostname = $this->getClientHostname($ip); if (!strcmp($hostname,"")) $error = 1; if (!$error) { # $country = $this->getctrybyhost($hostname); $country = strtolower($this->getctrycodebyhost($hostname)); return $country; } //else return false; } function getClientFlag($size) { $error = 0; $hostname = $this->getClientHostname(); if (!strcmp($hostname,"")) $error = 1; if (!$error) { $country_code = strtolower($this->getctrycodebyhost($hostname)); $file_name = $this->flag_dirs[$size] . '/' . $country_code . '.' . $this->flag_ext; if (is_readable($file_name)) { return $file_name; } } //else return false; } function getClientFlagHTML($size) { $error = 0; $flag = $this->getClientFlag($size); if (!strcmp($flag,"")) $error = 1; if (!$error) { return ''; } //else return false; } };