Академический Документы
Профессиональный Документы
Культура Документы
{ sales@ip2location.com }
The number of companies moved their business online is increasing. Selling products to
world wide is dealing with multi national customers and currencies. However, some
customers may have difficulty to convert the currency displayed to their origin currency.
It’s user friendly to show the pricing in a website in visitor origin currency. With the
origin currency, visitors can navigate faster and feel comfortable to make comparison.
In this tutorial, we use the IP2Location™ IP-Country database to lookup country of origin
from the visitor's IP address. Instead of loading the full database with 50000+ records,
we could simplify this tutorial with assumption only two different IP address ranges in
the world. IP addresses 0.0.0.0 - 126.255.255.255 originate from United States.
Meanwhile, IP addresses 127.0.0.0 - 255.255.255.255 originate from Japan. Here we
are creating a database "IP2Location" with table "IPCountry" that consists of two IP
address range records.
Step 1: Create and connect to 'IP2Location' database
mysql> CREATE DATABASE IP2Location
mysql> CONNECT IP2Location
Linux/Unix:
mysql> LOAD DATA INFILE "/IPCountry.csv" INTO TABLE IPCountry FIELDS
TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';
<?php
// Replace this MYSQL server variables with actual configuration
$mysql_server = "mysql_server.com";
$mysql_user_name = "UserName";
$mysql_user_pass = "Password";
// SQL query string to match the recordset that the IP number fall between
the valid range
$query = "SELECT * FROM IPCountry WHERE $ipno <= ipTO AND $ipno>=ipFROM";
// SQL query string to match the recordset that the TLD with Country Short
Name
$query = "SELECT * FROM Countries WHERE TLD='$countrySHORT';
// Execute SQL query
$result = mysql_query($query) or die("IP2Location Query Failed");