All pastes #2096493 Raw Edit

Mine

public text v1 · immutable
#2096493 ·published 2011-12-26 20:09 UTC
rendered paste body
function get_country($ip=null) {
        if(!$ip) return null;        
        
        if($this->getConf('geoplugin')) {        
            $country_data = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' .$ip));        
            return (array('code'=>$country_data['geoplugin_countryCode'],'name'=>$country_data['geoplugin_countryName']));
        }
        
        if($this->getConf('geoip_local')) {
             $giCity = geoip_open(QUICK_STATS. 'GEOIP/GeoLiteCity.dat',GEOIP_STANDARD);        
        }
        else {
            $gcity_dir = $this->getConf('geoip_dir');                
            $gcity_dat=rtrim($gcity_dir, "\040,/\\") . $this->NL  . 'GeoLiteCity.dat';                        
           //$giCity = geoip_open("/usr/local/share/GeoIP/GeoLiteCity.dat",GEOIP_STANDARD);
           $giCity = geoip_open($gcity_dat,GEOIP_STANDARD);
        }
        
        $record = geoip_record_by_addr($giCity, $ip);     
        if(!isset($record)) {
             return array();
        }
        return (array('code'=>$record->country_code,'name'=>$record->country_name));
    }