Advertisement
hexasoft

Display Country Currency Using PHP and BIN

May 16th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. /****************************************************************************************************************/
  2. /* Description: This snippet is provide simple way to help user display Visitor's Country Currency.             */
  3. /*              suggestions for different city locations across the country.                                    */
  4. /*              There are 1 steps in this snippet. For information, please visit IP2Location tutorial page at:  */
  5. /* https://www.ip2location.com/tutorials/display-visitors-country-currency-using-php-and-bin-database           */
  6. /****************************************************************************************************************/
  7. /* You can obtain free IP2Location LITE database for bin at https:https://lite.ip2location.com/                 */
  8. /* You can obtain free IP2Location PHP class module data at https://www.ip2location.com/developers/php          */
  9.  
  10. <?php
  11.     // Preset PHP settings
  12.     error_reporting(E_ALL);
  13.     ini_set('display_errors', 1);
  14.     set_time_limit(0);
  15.  
  16.     require_once('IP2Location.php');
  17.  
  18.     // Standard lookup with no cache
  19.     $loc = new \IP2Location\Database('./databases/IP2LOCATION-LITE-DB1.BIN', \IP2Location\Database::FILE_IO);
  20.  
  21.     $ip = $_SERVER['REMOTE_ADDR'];
  22.  
  23.     //lookup for country code
  24.     $country_code = $loc->lookup($ip, \IP2Location\Database::COUNTRY_CODE);
  25.  
  26.     //Lookup and display country code and country name
  27.     echo "Country Code: " . $loc->lookup($ip, \IP2Location\Database::COUNTRY_CODE) . "<br />";
  28.     echo "Country Name: " . $loc->lookup($ip, \IP2Location\Database::COUNTRY_NAME) . "<br />";
  29.  
  30.     //Displaying currency code based on country code retrieved.
  31.     //If no record of currency code or no country code is found, default will be used.
  32.     switch($country_code)
  33.     {
  34.         case 'CA':
  35.             $currency_code = "CAD";
  36.             echo "Country Currency: $currency_code 100";
  37.             break;
  38.         case 'MY':
  39.             $currency_code = "MYR";
  40.             echo "Country Currency: $currency_code 100";
  41.             break;
  42.         case 'JP':
  43.             $currency_code = "JPY";
  44.             echo "Country Currency: $currency_code 100";
  45.             break;
  46.         case 'US':
  47.             $currency_code = "USD";
  48.             echo "Country Currency: $currency_code 100";
  49.             break;
  50.         default:
  51.             echo "Unable to translate IP to country. <br />";
  52.             echo "$100.00";
  53.             break;
  54.     }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement