Wednesday, November 18, 2009

Targeted Online Advertising by Country using .NET Framework in VB.NET or C#


The global nature of websites is such that to maximize your earnings from online advertisements, you have to display different advertisements for visitors from different countries. This way, your web visitors will only see advertisements that are relevant to their country and thus be more inclined to click on those advertisements. In the long term, this will help to boost your revenue from the advertisements.

In this example, we will use a fully functional IP2Location™ .NET component available at http://www.ip2location.net/download/IP2LocationDotNetComponent.ZIP to determine the visitor’s country by their IP address. Firstly, install the IP2Location™ .NET component. Once installation is complete, get the IP2Location.DLL .NET component and sample database from the directory, i.e. C:\Program Files\IP2Location by default. You need to add a reference to this component from your Visual Studio web project. A copy of this component will be copied into /bin directory under the project. If the component is unregistered, there is a random 5-second delay in one out of ten queries.

To avoid any delays in the query, you can consider purchasing the IP2Location™ .NET Component Version 3.0, which is a software development component and data solution for .NET Framework. You can then dynamically tailor the content of your site based on your visitors country, region, city, latitude, longitude, ZIP code, ISP, domain name, timezone, connection speed, IDD code, area code, weather statation code, and weather station name.



Below is the sample code in VB.NET and C# webform which will display the targeted online advertising by country.

Sample Codes in VB.NET Webform

Imports IP2Location
Private Sub Query(ByVal strIPAddress As String)
    Dim oIPResult As New IP2Location.IPResult

    Try
        If strIPAddress <> "" Then
            IP2Location.Component.IPDatabasePath = "C:\\Program Files\\IP2Location\\Database\\IP-COUNTRY.SAMPLE.BIN"
            oIPResult = IP2Location.Component.IPQuery(strIPAddress)

            Select Case oIPResult.Status
                Case "OK"
                    If oIPResult.CountryShort = "JP" Then
                        ' Visitor is from Japan
                        ' Show advertisement from JP
                        Response.Write "<img src=""Japan.jpg"" border=""0"" height=""200"" width=""100"" />"
                    Else
                        ' Visitor is not from Japan
                        ' Show other advertisement
                        Response.Write "<img src=""US.jpg"" border=""0"" height=""200"" width=""100"" />"
                    End If
                Case "EMPTY_IP_ADDRESS"
                    Response.Write("IP Address cannot be blank.")
                Case "INVALID_IP_ADDRESS"
                    Response.Write("Invalid IP Address.")
                Case "MISSING_FILE"
                    Response.Write("Invalid Database Path.")
            End Select
        Else
            Response.Write("IP Address cannot be blank.")
        End If
    Catch ex As Exception

    Finally
        oIPResult = Nothing
    End Try
End Sub

Sample Codes in C# Webform

Using IP2Location;
private void Query(string strIPAddress)
{
    IPResult oIPResult = new IP2Location.IPResult();

    try
    {
        if (strIPAddress != "")
        {
            IP2Location.Component.IPDatabasePath = "C:\\Program Files\\IP2Location\\Database\\IP-COUNTRY.SAMPLE.BIN";
            oIPResult = IP2Location.Component.IPQuery(strIPAddress);

            switch(oIPResult.Status.ToString())
            {
                case "OK":
                    if (oIPResult.CountryShort == "JP") {
                        Response.Write "<img src="Japan.jpg" border="\" height="\" width="\" />"
                    }
                    else {
                        Response.Write "<img src="US.jpg" border="\" height="\" width="\" />"
                    }
                    break;
                case "EMPTY_IP_ADDRESS":
                    Response.Write("IP Address cannot be blank.");
                    break;
                case "INVALID_IP_ADDRESS":
                    Response.Write("Invalid IP Address.");
                    break;
                case "MISSING_FILE":
                    Response.Write("Invalid Database Path.");
                    break;
            }
        }
        else {
            Response.Write("IP Address cannot be blank.");
        }
    }
    catch(Exception ex)
    {
        ;
    }
    finally
    {
        oIPResult = null;
    }
}

IP2Location also carries a wide variety of databases which are more advanced and has more types of data which could also be used to further narrow down your target audience. If you want to try out the online demo, you can go to http://www.ip2location.com/demo.aspx and check it out.




Optimize Online Advertising Campaign by Country using PHP and MySQL Database

Let’s say you are coming from an English speaking country and you visit a website that shows you advertisements in a foreign language that you don’t understand. You would just ignore those advertisements like any normal person would. To the website owner, this is a lost opportunity to earn some money. That is why it is so vital to be able to match your web visitors with online advertisements that they will find relevant and useful. One way to do this is to show one set of advertisements for visitors from one country and then show another set to visitors from another country.

In this tutorial, we will use the IP2Location™IP-Country database to determine the country of origin for the web visitor just by checking the IP address. Instead of loading the full database with 50000+ records, we could simplify this tutorial with the assumption that only two different IP address ranges in the world. IP addresses of the range 0.0.0.0 - 126.255.255.255 originates from the United States. Meanwhile, IP addresses of the range 127.0.0.0 - 255.255.255.255 originates from Japan. Here we are creating a database called "IP2Location" with a table called "IPCountry" which contains our two IP address range records.


Step 1: Start the mysql command prompt. Run the 2 SQL command below to create the ‘IP2Location’ database and select it for use.

mysql> CREATE DATABASE IP2Location
mysql> CONNECT IP2Location


Step 2: Next, run the SQL statement below to create the ‘IPCountry’ table.

mysql> CREATE TABLE IPCountry
--> (
--> ipFROM DOUBLE NOT NULL,
--> ipTO DOUBLE NOT NULL,
--> countrySHORT VARCHAR(2) NOT NULL,
--> countryLONG VARCHAR(100) NOT NULL,
--> PRIMARY KEY(ipFROM, ipTO)
--> );



Step 3: Run the SQL codes below to insert dummy data into the database.

mysql> INSERT INTO IPCountry VALUES (0, 2130706431,'US','UNITED STATES');
mysql> INSERT INTO IPCountry VALUES (2130706432, 4294967295,'JP','JAPAN');


The full version of IP-Country database is available for subscription at $49/year from http://www.ip2location.com/ip-country.aspx.




If you have the full version of IP2Location™IP-Country database, the import process is easier by using the LOAD DATA feature available in MYSQL.

PC:
mysql> LOAD DATA INFILE "/IPCountry.csv" INTO TABLE IPCountry FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

Linux/Unix:
mysql> LOAD DATA INFILE "/IPCountry.csv" INTO TABLE IPCountry FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';


Below is a sample code in PHP which will show you how to use the data to optimize your online advertising campaign by country.

<%php
// Replace this MYSQL server variables with actual configuration
$mysql_server = "mysql_server.com";
$mysql_user_name = "UserName";
$mysql_user_pass = "Password";

// Retrieve visitor IP address from server variable REMOTE_ADDR
$ipaddress = getenv(REMOTE_ADDR);

// Convert IP address to IP number for querying database
$ipno = Dot2LongIP($ipaddress);

// Connect to the database server
$link = mysql_connect($mysql_server, $mysql_user_name, $mysql_user_pass) or die("Could not connect to MySQL database");

// Connect to the IP2Location database
mysql_select_db("IP2Location") or die("Could not select database");

// 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";

// Execute SQL query
$result = mysql_query($query) or die("IP2Location Query Failed");

// Retrieve the recordset (only one)
$row = mysql_fetch_object($result);

// Keep the country information into two different variables
$countrySHORT = $row->countrySHORT;
$countryLONG = $row->countryLONG;

// Free recordset and close database connection
mysql_free_result($result); mysql_close($link);

if ($countrySHORT == "JP")
{
// If the visitors are from JP, show advertisement from JP
echo "<img src="Japan.jpg" border="0" height="200" width="100">";
}
else {
// Otherwise, show other advertisement
echo "<img src="US.jpg" border="0" height="200" width="100">";
}
exit;

// Function to convert IP address (xxx.xxx.xxx.xxx) to IP number (0 to 256^4-1)
function Dot2LongIP ($IPaddr) {
if ($IPaddr == "")
{
return 0;
} else {
$ips = split ("\.", "$IPaddr");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}
%>

IP2Location also carries a wide variety of databases which are more advanced and has more types of data which could also be used to further narrow down your target audience. If you want to try out the online demo, you can go to http://www.ip2location.com/demo.aspx and check it out.



Niche Advertising by Country using ASP and MS-SQL Database

Online advertisements are a big revenue earner for most websites. So it is no wonder that most of them employ ways to detect their web visitor’s country so that the advertisements can be targeted to its niche audience. By doing so, the probability of a sale from the online advertisement increases tremendously as the targeted audience would most likely find that advertisement to be relevant and maybe even helpful.

In this tutorial, we will use the IP2Location™IP-Country database to determine the country of origin for the web visitor just by checking the IP address. Instead of loading the full database with 50000+ records, we could simplify this tutorial with the assumption that only two different IP address ranges in the world. IP addresses of the range 0.0.0.0 - 126.255.255.255 originates from the United States. Meanwhile, IP addresses of the range 127.0.0.0 - 255.255.255.255 originates from Japan. Here we are creating a database called "IP2Location" with a table called "IPCountry" which contains our two IP address range records.


Step 1: Start Microsoft SQL Server Management Studio.

Now, login to your database instance and then click on the New Query button. Copy the 2 lines of SQL codes below into the query window and press Execute to run the codes. This will create the ‘IP2Location’ database and select it for use.

CREATE DATABASE IP2Location
GO
USE IP2Location
GO




Step 2: Next, run the SQL statement below to create the ‘IPCountry’ table.

CREATE TABLE[dbo].[IPCountry] (
[ipFROM] [float] NOTNULL ,
[ipTO] [float] NOT NULL ,
[countrySHORT] [nvarchar] (2),
[countryLONG] [nvarchar] (64)
) ON [PRIMARY]
GO



Step 3: Run the SQL codes below to insert dummy data into the database.

INSERT INTO IPCountry VALUES (0, 2130706431,'US','UNITED STATES');
INSERT INTO IPCountry VALUES (2130706432, 4294967295,'JP','JAPAN');



The full version of IP-Country database is available for subscription at $49/year from http://www.ip2location.com/ip-country.aspx. If you have the full version of IP2Location™IP-Country database, import process is easy done by using the Database Transformation Service (DTS) in MS-SQL.



In your ASP page, you will need to put in the codes below.

<%
Dim conn, myDSN, mySQL, rs

' SQL database connection. NOTE: Replace servername, username and password to your own values.
Set conn = Server.CreateObject("ADODB.Connection")

myDSN="DRIVER={SQLServer};SERVER=servername;UID=username;PWD=password;DATABASE=IP2Location"

conn.open myDNS

' retrieve visitor IP address and translate it to IP address number
IPno = Dot2LongIP(Request.ServerVariables("REMOTE_ADDR"))

' SQL query to lookup valid range of IP address
mySQL = "SELECT countrySHORT FROM IPCountry WHERE " & IPno & " BETWEEN ipFROM AND ipTO"

Set rs = Server.CreateObject("ADODB.Recordset")
rs.open mySQL, conn

' assign country name for reference
countryName = rs("countrySHORT")

' close and free connections
rs.close
conn.close
set rs = nothing
Set conn = nothing

If CountryName = "JP" Then
' Visitor is from Japan
' Show advertisement from Japan
response.write "<img src=""Japan.jpg"" border=""0"" height=""200"" width=""100"">"
Else
' Visitor is not from Japan
' Show other advertisement
response.write "<img src=""US.jpg"" border=""0"" height=""200"" width=""100"">"
End If
%>

Function Dot2LongIP (ByVal DottedIP)
Dim i, pos
Dim PrevPos, num
If DottedIP = "" Then
Dot2LongIP = 0
Else
For i = 1 To 4
pos = InStr(PrevPos + 1, DottedIP, ".", 1)
If i = 4 Then
pos = Len(DottedIP) + 1
End If
num = Int(Mid(DottedIP, PrevPos + 1, pos - PrevPos - 1))
PrevPos = pos
Dot2LongIP = ((num Mod 256) * (256 ^ (4 - i))) + Dot2LongIP
Next
End If
End Function
%>

IP2Location also carries a wide variety of databases which are more advanced and has more types of data which could also be used to further narrow down your target audience. You can try out the online demo at http://www.ip2location.com/demo.aspx and see for yourself what you are missing.




Display Advertisement by Country using ASP and COM Technology

IP2Location™ ActiveX/COM DLL
Online advertisements these days are now raking in the big bucks due to the simple fact that it is now possible to display different advertisements to web visitors from different countries. By showing an advertisement that is relevant to the web visitor, there is a higher chance that it will attract the attention of the web visitor which tends to lead to a sale.

In this example, we use a fully functional IP2Location™ActiveX component available at http://www.ip2location.com/ip2location-country.zip to determine the visitor’s country by their IP address. Since the component is unregistered, there is a 5-second delay in every query.

To avoid any delays in the query, you can consider purchasing the IP2Location ActiveX/COM Component Version 3.0, which is a software development component and data solution for Windows®. You can tailor the content of your site dynamically based on visitor’s country, region, city, latitude, longitude, ZIP code, ISP, domain name, time zone, connection speed, IDD code, area code, weather station code and weather station name.



Copy the ActiveX component to the IIS web server. Then run the following command in DOS prompt.

C:\> regsvr32 ip2location.dll


Below is the sample code in ASP which will display advertisement by country.

<% ' Create server-side object Set ipObj = Server.CreateObject("IP2Location.Country") ' Initialize IP2Location object If ipObj.Initialize("demo") <> "OK" Then
response.write "IP2Location Initialization Failed."
End If

' Get visitor's IP address
IPaddr = Request.ServerVariables("REMOTE_ADDR")

' Detect visitor's country of origin by IP address
CountryName = ipObj.LookUpShortName(IPaddr)

' Free IP2Location object
Set ipObj = nothing

If CountryName = "JP" Then
' Visitor is from Japan
' Show advertisement from Japan
response.write "<img src=""Japan.jpg"" border=""0"" height=""200"" width=""100"">"
Else
' Visitor is not from Japan
' Show other advertisement
response.write "<img src=""US.jpg"" border=""0"" height=""200"" width=""100"">"
End If
%>

IP2Location also carries a wide variety of databases which are more advanced and has more types of data which could also be used to further narrow down your target audience. If you want to try out the online demo, you can go to http://www.ip2location.com/demo.aspx and check it out.




Tuesday, November 17, 2009

Displaying the Currency Type by Visitor's Country using PHP and MYSQL Database

More and more companies have started to take their businesses online which bring about significant cost reductions as opposed to traditional businesses. In addition, there is now an opportunity to take your products or services and market them to a larger audience of prospective customers from all over the world. To become a successful global player, online business owners need automatic IP-Country detection for localized currency type which will help them to boost their online sales by removing the foreign currency conversion barrier and converting their website visitors into buyers.

In this tutorial, we will use the IP2Location™IP-Country database to determine the country of origin for the web visitor just by checking the IP address. Instead of loading the full database with 50000+ records, we could simplify this tutorial with the assumption that only two different IP address ranges in the world. IP addresses of the range 0.0.0.0 - 126.255.255.255 originates from the United States. Meanwhile, IP addresses of the range 127.0.0.0 - 255.255.255.255 originates from Japan. Here we are creating a database called "IP2Location" with a table called "IPCountry" which contains our two IP address range records.


Step 1: Start the mysql command prompt. Run the 2 SQL command below to create the ‘IP2Location’ database and select it for use

mysql> CREATE DATABASE IP2Location ;
mysql> CONNECT IP2Location;


Step 2: Next, run the SQL statement below to create the ‘IPCountry’ table

mysql> CREATE TABLE IPCountry
--> (
--> ipFROM DOUBLE NOT NULL,
--> ipTO DOUBLE NOT NULL,
--> countrySHORT VARCHAR(2) NOT NULL,
--> countryLONG VARCHAR(100) NOT NULL,
--> PRIMARY KEY(ipFROM, ipTO)
--> );



Step 3: Run the SQL codes below to insert dummy data into the database

mysql> INSERT INTO IPCountry VALUES (0, 2130706431,'US','UNITED STATES');
mysql> INSERT INTO IPCountry VALUES (2130706432, 4294967295,'JP','JAPAN');


The full version of IP-Country database is available for subscription at $49/year from http://www.ip2location.com/ip-country.aspx.



If you have the full version of IP2Location™ IP-Country database, the import process is easier by using the LOAD DATA feature available in MYSQL.

PC:
mysql> LOAD DATA INFILE "/IPCountry.csv" INTO TABLE IPCountry FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

Linux/Unix:
mysql> LOAD DATA INFILE "/IPCountry.csv" INTO TABLE IPCountry FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';


Step 4: Run the SQL statement below to create the 'Countries' table

mysql> CREATE TABLE Countries
--> (
--> TLD VARCHAR(2) NOT NULL,
--> Country VARHCAR(100) NOT NULL,
--> FIPS104 VARCHAR(2) NOT NULL,
--> ISO2 VARCHAR(2) NOT NULL,
--> ISO3 VARCHAR(3) NOT NULL,
--> ISONo INT NOT NULL,
--> Capital VARCHAR(100) NOT NULL,
--> Region VARCHAR(100) NOT NULL,
--> Currency VARCHAR(50) NOT NULL,
--> CurrencyCode VARCHAR(3) NOT NULL,
--> Population DOUBLE NOT NULL,
--> );



The country information is available for FREE at http://www.ip2location.com/countryinformation.aspx . It consists of the top level domain (TLD), ISO-3166, country, capital, region, currency, currency code and population. Download and load the data into your database. It's available in several formats such as Comma-delimited ASCII, Microsoft® Access & Microsoft® Excel. The import process is same as the IP-Country database by using the LOAD DATA feature available in MYSQL.



You can use the SQL statement below to import the country information into the database.

mysql> LOAD DATA INFILE "/Countries.csv" INTO TABLE Countries FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r';

Below is a sample code in PHP which will show you how to use the data to determine the correct currency to display the pricing.

<?php
// Replace this MYSQL server variables with actual configuration
$mysql_server = "mysql_server.com";
$mysql_user_name = "UserName";
$mysql_user_pass = "Password";

// Retrieve visitor IP address from server variable REMOTE_ADDR
$ipaddress = getenv(REMOTE_ADDR);

// Convert IP address to IP number for querying database
$ipno = Dot2LongIP($ipaddress);

// Connect to the database server
$link = mysql_connect($mysql_server, $mysql_user_name, $mysql_user_pass) or die("Could not connect to MySQL database");

// Connect to the IP2Location database
mysql_select_db("IP2Location") or die("Could not select database");

// 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";

// Execute SQL query
$result = mysql_query($query) or die("IP2Location Query Failed");

// Retrieve the recordset (only one)
$row = mysql_fetch_object($result);

// Keep the country information into two different variables
$countrySHORT = $row->countrySHORT;
$countryLONG = $row->countryLONG;
// 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");

// Retrieve the recordset (only one)
$row = mysql_fetch_object($result);

// Keep the Currency Code in a variable
$currencyCode = $row->CurrencyCode;

// Free recordset and close database connection
mysql_free_result($result); mysql_close($link);

// If the visitors are from JP
if ($countrySHORT == "JP")
{
//Print Price: YEN 120.00
echo “Price: $currentCode 120.00”;
}
else
{
// Otherwise
//Print USD 1.00
echo “Price: $currentCode 1.00”;
}
exit;

// Function to convert IP address (xxx.xxx.xxx.xxx) to IP number (0 to 256^4-1)
function Dot2LongIP ($IPaddr) {
if ($IPaddr == "")
{
return 0;
} else {
$ips = split ("\.", "$IPaddr");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}
?>

What you have seen here today is just the tip of the iceberg of what you can do with the IP2Location™IP-Country database. You could even pair the code above with a forex service to get a real-time conversion rate for the currencies thus making your currency conversions even more up-to-date. Now that you have realized the power of the IP2Location™IP-Country database, you will benefit even more from the more advanced databases available from IP2Location. You can try out the online demo at http://www.ip2location.com/demo.aspx and see for yourself what you are missing.



Monday, November 16, 2009

Show Visitor's Country Currency Using ASP and MS-SQL 2008 Database

More and more companies are realizing the importance of doing business online as a way of improving their market share. With this realization comes the need to deal with customers from around the world and their various currencies. This is when being able to show the pricing on a website in the visitor’s local currency would make the online shopping experience more user-friendly; eliminating the usual headache of foreign currency conversion.

In this tutorial, we will use the IP2Location™IP-Country database to determine the country of origin for the web visitor just by checking the IP address. Instead of loading the full database with 50000+ records, we could simplify this tutorial with the assumption that only two different IP address ranges in the world. IP addresses of the range 0.0.0.0 - 126.255.255.255 originates from the United States. Meanwhile, IP addresses of the range 127.0.0.0 - 255.255.255.255 originates from Japan. Here we are creating a database called "IP2Location" with a table called "IPCountry" which contains our two IP address range records.


Step 1: Start Microsoft SQL Server Management Studio.

Now, login to your database instance and then click on the New Query button. Copy the 2 lines of SQL codes below into the query window and press Execute to run the codes. This will create the ‘IP2Location’ database and select it for use.

CREATE DATABASE IP2Location
GO
USE IP2Location
GO




Step 2: Next, run the SQL statement below to create the ‘IPCountry’ table.

CREATE TABLE[dbo].[IPCountry] (
[ipFROM] [float] NOTNULL ,
[ipTO] [float] NOT NULL ,
[countrySHORT] [nvarchar] (2),
[countryLONG] [nvarchar] (64)
) ON [PRIMARY]
GO



Step 3: Run the SQL codes below to insert dummy data into the database.

INSERT INTO IPCountry VALUES (0, 2130706431,'US','UNITED STATES');
INSERT INTO IPCountry VALUES (2130706432, 4294967295,'JP','JAPAN');



The full version of IP-Country database is available for subscription at $49/year from http://www.ip2location.com/ip-country.aspx.




Step 4: Run the SQL statement below to create the 'Countries' table

CREATE TABLE [dbo].[Countries] (
[TLD] [nvarchar] (3),
[Country][nvarchar] (100),
[FIPS104][nvarchar] (2),
[ISO2] [nvarchar] (2),
[IOS3] [nvarchar] (3),
[Capital] [nvarchar] (100),
[Region] [nvarchar] (100),
[Currency] [nvarchar] (50),
[CurrencyCode] [nvarchar] (3),
[Population] [int]
) ON [PRIMARY]
GO



The country information is available for FREE at http://www.ip2location.com/countryinformation.aspx . It consists of the top level domain (TLD), ISO-3166, country, capital, region, currency, currency code and population. Download and load the data into your database. It's available in several formats such as Comma-delimited ASCII, Microsoft® Access & Microsoft® Excel.



In your ASP page, you will need to put in the codes below.

<%


Dim conn, myDSN, mySQL, rs, mySQL2, rs2


' SQL database connection. NOTE: Replace servername, username and password to your own values.

Set conn = Server.CreateObject("ADODB.Connection")

myDSN="DRIVER={SQLServer};SERVER=servername;UID=username;PWD=password;DATABASE=IP2Location"


conn.open myDNS


' retrieve visitor IP address and translate it to IP address number

IPno = Dot2LongIP(Request.ServerVariables("REMOTE_ADDR"))


' SQL query to lookup valid range of IP address

mySQL = "SELECT countrySHORT FROM IPCountry WHERE " & IPno & " BETWEEN ipFROM AND ipTO"

Set rs = Server.CreateObject("ADODB.Recordset")

rs.open mySQL, conn


' assign country name for reference

countryName = rs("countrySHORT")


' SQL query to lookup currency code

mySQL2 = "SELECT CurrencyCode FROM Countries WHERE TLD='" & countryName & "'"


Set rs2 = Server.CreateObject("ADODB.Recordset")

rs2.open mySQL2, conn


' assign currency code for reference

currencyCode = rs("currencyCode")


' close and free connections

rs.close

rs2.close

conn.close

set rs = nothing

set rs2 = nothing

Set conn = nothing


If CountryName = "JP" Then ' Visitor is from Japan

' Show price in YEN

Response.Write "Price: " & currencyCode & " 120.00"

Else ' Visitor is not from Japan

' Show price in USD

Response.Write "Price: " & currencyCode & " 1.00"

End If


Function Dot2LongIP (ByVal DottedIP)

Dim i, pos

Dim PrevPos, num

If DottedIP = "" Then

Dot2LongIP = 0

Else

For i = 1 To 4

pos = InStr(PrevPos + 1, DottedIP, ".", 1)

If i = 4 Then

pos = Len(DottedIP) + 1

End If

num = Int(Mid(DottedIP, PrevPos + 1, pos - PrevPos - 1))

PrevPos = pos

Dot2LongIP = ((num Mod 256) * (256 ^ (4 - i))) + Dot2LongIP

Next

End If

End Function %>

What you have seen here today is just the tip of the iceberg of what you can do with the IP2Location™IP-Country database. You could even pair the code above with a forex service to get a real-time conversion rate for the currencies thus making your currency conversions even more up-to-date. Now that you have realized the power of the IP2Location™IP-Country database, you will benefit even more from the more advanced databases available from IP2Location. You can try out the online demo at http://www.ip2location.com/demo.aspx and see for yourself what you are missing.



Tuesday, October 6, 2009

IP2Location 封锁来自特定国家的在线访客

如果你发现来自某些国家的网络用户经常::

发送垃圾邮件,不相关或不适当的信息到你网站的电子邮件
从你的网站下载了大量的数据
从你的网站的下载页面上窃取你的数码产品
盗取你的软件并非法分发或享用
通过链接直接在自己的网站上使用你的服务器上的图像,在同一时间内窃取你的图像并使用你的带宽
利用垃圾信息发布机骚扰你的网站

实际上,你可以使用IP2Location所提供的封锁来自特定国家的在线访客免费服务阻止及控制来自某些国家在线访客的 恶意流量到你的网站以便节省你网络的带宽资源。

不仅如此,但你也可以利用这个服务来限制你的网站访客,如果你在网上所销售的产品只限定于某些地区或国家。

只需两个简单的步骤就能制作免费的htaccess文件。首先,选择你所想要阻止的访客的国家名单,你可以选择30个国家,如果你注册一个IP2Location免费帐户


然后选择你的输出格式: htaccessiptablesCIDR格式


按”Generate”按钮,复制并粘贴数据输出到你的外部文件中。


IP2Location封锁来自特定国家的在线访客提供免费下载最新的国家清单。我们的数据是检索自最新最全面的IP2Location数据库。IP2Location数据库每月更新一次,以确保数据库的高精度。你可以有效地封锁来自特定国家不必要或恶意的流量。这样的活动包括网上猖獗寄送垃圾邮件,以及类似于肆虐盗窃信用卡或个人隐私,用户的帐号和密码这样的犯罪行为。


如果你想在IIS 互联网信息服务器上封锁来自特定国家的在线访客 ,您可以查询IP2LocationISAPI FilterIP2Location ISAPI Filter是一个互联网服务器应用程序编程接口(ISAPI)插件,可以运行在任何使用IIS 互联网信息服务器上。它能让你从在线访问者的IP地址轻松获取其确切的地理位置信息。它使用服务器字段,让你能够根据访问者的国家,地区,城市,纬度,经度,邮政编码,互联网服务提供商,域名等地理位置信息来设定或更改页面内容。