/****************************************************************************************************************/
/* Description: This snippet is provide simple way to help user display Visitor's Country Currency. */
/* suggestions for different city locations across the country. */
/* There are 1 steps in this snippet. For information, please visit IP2Location tutorial page at: */
/* https://www.ip2location.com/tutorials/display-visitors-country-currency-using-php-and-bin-database */
/****************************************************************************************************************/
/* You can obtain free IP2Location LITE database for bin at https:https://lite.ip2location.com/ */
/* You can obtain free IP2Location PHP class module data at https://www.ip2location.com/developers/php */
lookup($ip, \IP2Location\Database::COUNTRY_CODE);
//Lookup and display country code and country name
echo "Country Code: " . $loc->lookup($ip, \IP2Location\Database::COUNTRY_CODE) . "
";
echo "Country Name: " . $loc->lookup($ip, \IP2Location\Database::COUNTRY_NAME) . "
";
//Displaying currency code based on country code retrieved.
//If no record of currency code or no country code is found, default will be used.
switch($country_code)
{
case 'CA':
$currency_code = "CAD";
echo "Country Currency: $currency_code 100";
break;
case 'MY':
$currency_code = "MYR";
echo "Country Currency: $currency_code 100";
break;
case 'JP':
$currency_code = "JPY";
echo "Country Currency: $currency_code 100";
break;
case 'US':
$currency_code = "USD";
echo "Country Currency: $currency_code 100";
break;
default:
echo "Unable to translate IP to country.
";
echo "$100.00";
break;
}
?>