0

I am trying to get Current Country Code Magento 1

using below code

$currentCountry = GeoIP_Core::getInstance(Mage::getBaseDir('media') . DS . "geoip" . DS . "GeoLiteCity.dat", GeoIP_Core::GEOIP_STANDARD)
            ->geoip_country_code_by_addr(Mage::helper('core/http')->getRemoteAddr());
    }

But its not giving me proper country code,

Is their any way to get it ?

1

1 Answer 1

1

Try This:-

$ipAddress =  $_SERVER['REMOTE_ADDR'];
$json       = file_get_contents("http://ipinfo.io/{$ipAddress}/json");
$details    = json_decode($json);
if(isset($details->country)) {
    echo $details->country;
}

Thanks

6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.