init(); } public function init() { // Check ip-to-country.bin file $ip2c_bin_file = dirname(__FILE__) . '/ip2c/' .self::IP2C_BIN_FILE; if ( !file_exists($ip2c_bin_file) ) { $ip2c_bin_file = null; } $this->ip2c = new ip2country($ip2c_bin_file); } public function get_info($ip) { if ( !isset($this->ip2c) ) $this->init(); $res = $this->ip2c->get_country($ip); $ccode = $res != false ? $res['id2'] : null; unset($res); return array( $ccode ? $this->get_country_name($ccode) : null, $ccode ); } // Get country name private function get_country_name($country_code) { $res = $this->ip2c->find_country($country_code); return (isset($res['name']) ? $res['name'] : ''); } }